How to map property as NOT column in EF 4.1

I have a class:

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; } } } 

I can match PartyId and PartyDate, but I do not have a column for ArrivedCount (this is a point in time, it is not saved).

How to tell EF 4.1 to stop searching for a column named "ArrivedCount"? This is not in the table. It will not be in the table. This is just a property of the object and that’s it.

Thanks in advance.

EDIT: Here's the Fluent API configuration for classParty.

 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"); } } 
+6
source share
2 answers
 modelBuilder.Entity<classParty>().Ignore(x => x.ArrivedCount); 
+8
source

With data annotations:

 [NotMapped] public int ArrivedCount //... 

Or using the Fluent API:

 modelBuilder.Entity<classParty>() .Ignore(c => c.ArrivedCount); 
+14
source

Source: https://habr.com/ru/post/903452/


All Articles