Entity Framework 6 NotMapped attributes

ef-fluent-api entity-framework entity-framework-6 fluent

Question

Is there a way using the fluentAPI within a DbContext to manually include ICollections that have been [NotMapped] in the model? I know how to manually ignore properties using the fluentAPI

modelBuilder.Entity<MyEntity>().Ignore(e => e.MyChildCollection);

But if the property was defined with the [NotMapped] attribute (see below), can it be "brought back" into the model?

[NotMapped]
public virtual ICollection<ChildEntityType> MyChildCollection { get; set; }
1
0
5/14/2015 11:12:20 AM

Popular Answer

Yes it can be. You just have to remove the [NotMapped] Data Annotation and then go to your Package Console Manager. Type add-migration [anyname]. Then type update-database. It will automatically make the changes.

0
5/14/2015 11:16:26 AM


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