Entity Framework 基地 Class
Entity Framework Base Class
有实体对象的基础 class 无论我有实体的复合 class,我都面临着循环引用和基础依赖角色引入问题:
public abstract class Base
{
public int Id {get;set;}
public DateTime CreationTime {get;set;}
public User Creator {get; ste;}
}
public class User : Base
{
public string Name {get;set;}
public Country BirthPlace {get;set;}
// rest of the properties
}
public class Country : Base
{
public string Description {get;set;}
//rest of the properties
}
知道如何克服这个问题吗?
创建映射 class 以忽略基础 class 用户
public class UserMap : EntityTypeConfiguration<User>
{
public UserMap()
{
Ignore(x => x.User);
}
}
或
从基础中删除用户并将其添加到需要它的每个域中(示例)
public class Country : Base
{
public string Description {get;set;}
public User Creator {get; set}
//rest of the properties
}
有实体对象的基础 class 无论我有实体的复合 class,我都面临着循环引用和基础依赖角色引入问题:
public abstract class Base
{
public int Id {get;set;}
public DateTime CreationTime {get;set;}
public User Creator {get; ste;}
}
public class User : Base
{
public string Name {get;set;}
public Country BirthPlace {get;set;}
// rest of the properties
}
public class Country : Base
{
public string Description {get;set;}
//rest of the properties
}
知道如何克服这个问题吗?
创建映射 class 以忽略基础 class 用户
public class UserMap : EntityTypeConfiguration<User>
{
public UserMap()
{
Ignore(x => x.User);
}
}
或
从基础中删除用户并将其添加到需要它的每个域中(示例)
public class Country : Base
{
public string Description {get;set;}
public User Creator {get; set}
//rest of the properties
}