如何将属性映射为不是EF 4.1中的列

Tom*_*lla 6 c# mapping entity-framework-4

我有一节课:

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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我可以映射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");
    }
}
Run Code Online (Sandbox Code Playgroud)

Sla*_*uma 14

使用数据注释:

[NotMapped]
public int ArrivedCount
//...
Run Code Online (Sandbox Code Playgroud)

或者使用Fluent API:

modelBuilder.Entity<classParty>()
    .Ignore(c => c.ArrivedCount);
Run Code Online (Sandbox Code Playgroud)


Luc*_*Sam 9

modelBuilder.Entity<classParty>().Ignore(x => x.ArrivedCount); 
Run Code Online (Sandbox Code Playgroud)