I want to have a Person entity in my model. There is no corresponding table and no discriminator. I simply want it as a common base class for some other entities to share (I want to define a public partial class Person
with common functionality.
So, for example, I want to have:
// this class has no corresponding table in the DB
public partial abstract class Person
{
public int Id {get; set;}
public string FirstName {get; set;}
public string LastName {get; set;}
public string DisplayName { get { return string.Format("{0}, {1}", LastName, FirstName); } }
}
// this corresponds to dbo.Users
public partial class User : Person
{
}
// this corresponds to dbo.Contacts
public 开发者_Go百科partial class Contact : Person
{
}
So, I created an abstract entity Person, set it as the base class for the User and Contact entities, then added my properties, and set my mappings for dbo.Users and dbo.Contacts for the PK Id, FirstName, and LastName properties.
I get the error:
3032: Problem in mapping fragments starting at lines 2109
..... are being mapped to the same rows in table .... Mapping conditions can be used to distinguish the rows that these types are mapped to.
How can I get this working?
You must define the Person
entity in EDMX file and inherit both User
and Contact
from the Person
in EDMX. None of properties defined in Person
can appear in inherited entity. Then go to mapping details and map inherited entities to corresponding tables.
Be aware that primary key now must be unique for all persons - not only in derived entities.
精彩评论