排除来自与实体框架4和数据库中的字段/属性; code-第一 [英] Exclude a field/property from the database with Entity Framework 4 & Code-First
本文介绍了排除来自与实体框架4和数据库中的字段/属性; code-第一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我会想知道,有没有办法排除从数据库中的某些字段?对于例如:
I will like to know that is there a way to exclude some fields from the database? For eg:
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public string FatherName { get; set; }
public bool IsMale { get; set; }
public bool IsMarried { get; set; }
public string AddressAs { get; set; }
}
我如何从数据库中排除AddressAs领域?
How can I exclude the AddressAs field from the database?
推荐答案
在当前版本的排除性的唯一方法是显式地映射所有其他列:
In the current version the only way to exclude a property is to explicitly map all the other columns:
builder.Entity<Employee>().MapSingleType(e => new {
e.Id,
e.Name,
e.FatherName,
e.IsMale,
e.IsMarried
});
由于AddressAs未被引用它不是实体/数据库的一部分。
Because AddressAs is not referenced it isn't part of the Entity / Database.
该EF队的考虑的补充是这样的:
The EF team is considering adding something like this:
builder.Entity<Employee>().Exclude(e => e.AddressAs);
我建议你告诉留在EFDesign博客评论,要求此功能:)
I suggest you tell leave a comment on the EFDesign blog, requesting this feature :)
希望这有助于
亚历
这篇关于排除来自与实体框架4和数据库中的字段/属性; code-第一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文