EF Code first NotMapped Attribute

.net c# ef-code-first entity-framework

Question

Why is in the following example the [NotMapped] attribute required:

public virtual ICollection<Blog> Blogs { get; set; }

[NotMapped]
    public List<Blog> NewBlogs{
        get{
            return Blogs.Where(x=>x.Date > DateTime.Now).ToList();
        }
    }

Without the [NotMapped] attribute I get an exception:

Invalid column name Blog_ID

The column name in the database is BlogID.

EDIT

I would expect, that properties without setter are never directly mapped to the database and automatically ignored by code first.

1
1
12/18/2013 2:52:08 PM

Popular Answer

with [NotMapped] attribute basically you mark that properties as not an Entity/Properties

so EF will not try to map/fetch that properties from database

that example actually say, NewBlogs is not Entity like Blogs. so stop try to get NewBlogs from database

5
12/18/2013 2:23:48 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow