开发者

With Entity Framework 4.1 Codefirst, how do you create unmapped fields in the poco classes?

I have a set of classes as my domain objects. I have a set of configuration files to map these objects (EntityTypeConfiguration<>).

When I add a property to any of the domain objects without mapping to a column, the dbcontext attempts to query for the column, ignoring the fact that it is not mapped.

I must be missing a setting either in the configuration code or the dbcontext code. I do not want to add an attribute to the poco class (decorating the pocos tie them to a specific persistence implementation, which I wish to avoid).

On the call against the IQueryable to populate a ticket object, the call fails with the message:

Invalid column name 'NotInDatabase'.

public class Ticket  
{  
    public Ticket() 
    {
    }

    public virtual int Id
    {
        get;
        set;
    }

    public virtual string Title
    {
        get;
        set;
    }

    public virtual string Description
    {
        get;
        set;
    }

    public string NotInDatabase
    {
        get;
        set;
    }
}


internal class TicketConfiguration : EntityTypeConfiguration<Ticket>  
{   
    public TicketCon开发者_StackOverflow社区figuration()  
    {  
        ToTable("ticket_table_name");

        HasKey(o => o.Id)
            .Property(o => o.Id)
            .HasColumnName("ticketId")
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
            .IsRequired();

        Property(o => o.Title).HasColumnName("TicketTitle");
        Property(o => o.Description).HasColumnName("TicketDescription");
    }   
}

Note: Please do not suggest using "Database First" or "Model First" for my situation. I want to map poco objects to the database using the features of code first, even though I have an existing db structure. I am comparing this to nhibernate and really want to stick to a similar structure (since Microsoft "adopted" fluent nhibernate's approach, it's pretty easy to compare apples to apples).

Thanks!


.Ignore should do the trick or by attribute it's called [NotMapped]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜