You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a legacy DB with some limited possibilities to change data structure. Suppose that you have a field called "Origin" in this example, which discriminates entities in different 2 child entities. An entity is an ItemA if it has 'X' or ' Y' in the Origin field.
Is possible to map child entities to have more than one value to discriminate the correct entity?
What I'm trying to configure is the following mapping:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Item>()
.HasDiscriminator<string>("origin")
.HasValue<ItemA>("X")
.HasValue<ItemA>("Y")
.HasValue<ItemB>("Z");
}
}
public abstract class Item
{
public int ItemId { get; set; }
public string Name { get; set; }
}
public class ItemA : Item
{
public string PropA { get; set; }
}
public class ItemB : Item
{
public string PropB { get; set; }
}
}
Currently it takes the last "hasValue" it sees (in this case for example 'Y' will be used as where clause) for searching ItemA entity, so it seems is not working properly. Do you have any tips or future feature which could be helpful in order to solve this scenario?
EF Core version: 3.1.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET Core 3.0
Operating system: Windows 10
IDE: Rider
The text was updated successfully, but these errors were encountered:
I understood now that there is a problem with this configuration. Once it has to save the entity it doesn't know what to save since it has two possible values ('X' or 'Y'). Close this request.
Thanks.
I have a legacy DB with some limited possibilities to change data structure. Suppose that you have a field called "Origin" in this example, which discriminates entities in different 2 child entities. An entity is an ItemA if it has 'X' or ' Y' in the Origin field.
Is possible to map child entities to have more than one value to discriminate the correct entity?
What I'm trying to configure is the following mapping:
Currently it takes the last "hasValue" it sees (in this case for example 'Y' will be used as where clause) for searching ItemA entity, so it seems is not working properly. Do you have any tips or future feature which could be helpful in order to solve this scenario?
EF Core version: 3.1.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET Core 3.0
Operating system: Windows 10
IDE: Rider
The text was updated successfully, but these errors were encountered: