I have an EDM Model where a Money object has a structure roughly as follows - this is quite a common domain modeling example I believe:
public class Money
{
public Currency Currency {get; set;}
public decimal Amount {get; set;}
}
Money is a value object whereas Currency is an entity with a database id. However, if I define my model as follows then my odata route is invalid.
var builder = new ODataConventionModelBuilder();
builder.EntitySet<Currency>("Currencies");
builder.ComplexType<Money>();
I get the following error:
The complex type 'Dealogic.DemoService.Model.Money' refers to the entity type 'Dealogic.DemoService.Model.Currency' through the property 'Currency'.
There are a couple of possible workarounds:
* Give the Money value object just a currency id (not ideal because money calculations need to work with currency fields)
* Give the Money value object a DummyId field and add it as an entity, as below (a hack that will lead to further problems)
EntityTypeConfiguration money = builder.AddEntity(typeof(Money));
money.AddProperty(entityType.GetProperty("DummyId"));
money.HasKey(entityType.GetProperty("DummyId"));
I just wondered if anyone else has run into this problem and how they have dealt with it? Will entities inside value objects be supported in the official release?
public class Money
{
public Currency Currency {get; set;}
public decimal Amount {get; set;}
}
Money is a value object whereas Currency is an entity with a database id. However, if I define my model as follows then my odata route is invalid.
var builder = new ODataConventionModelBuilder();
builder.EntitySet<Currency>("Currencies");
builder.ComplexType<Money>();
I get the following error:
The complex type 'Dealogic.DemoService.Model.Money' refers to the entity type 'Dealogic.DemoService.Model.Currency' through the property 'Currency'.
There are a couple of possible workarounds:
* Give the Money value object just a currency id (not ideal because money calculations need to work with currency fields)
* Give the Money value object a DummyId field and add it as an entity, as below (a hack that will lead to further problems)
EntityTypeConfiguration money = builder.AddEntity(typeof(Money));
money.AddProperty(entityType.GetProperty("DummyId"));
money.HasKey(entityType.GetProperty("DummyId"));
I just wondered if anyone else has run into this problem and how they have dealt with it? Will entities inside value objects be supported in the official release?