我有一个班级:
public class classParty
{
private int _arrivedCount;
public int PartyID {get; private set;}
public DateTime PartyDate {get; private set;}
public int ArrivedCount
{
get
{
return _arrivedCount;
}
set
{
_arrivedCount = value;
}
}
}
我可以映射PartyId和PartyDate,但是我没有ArrivedCount的列(这是一个时间点,它不会持久)。
如何告诉EF 4.1停止查找名为“ArrivedCount”的列?它不在桌子上。它不会出现在桌子上。它只是对象的一个属性,而且都是。
提前致谢。
编辑: 这是classParty的Fluent API配置。
public class PartyConfiguration : EntityTypeConfiguration<classParty>
{
public PartyConfiguration()
: base()
{
HasKey(p => p.PartyID);
Property(p => p.PartyID)
.HasColumnName("PartyID")
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
.IsRequired();
Property(p => p.PartyDate)
.HasColumnName("PartyDate")
.IsRequired();
ToTable("Party");
}
}
答案 0 :(得分:14)
使用数据注释:
[NotMapped]
public int ArrivedCount
//...
或使用Fluent API:
modelBuilder.Entity<classParty>()
.Ignore(c => c.ArrivedCount);
答案 1 :(得分:9)
modelBuilder.Entity<classParty>().Ignore(x => x.ArrivedCount);