As I mentioned here, I changed the structure of my ASP.NET MVC 5 app like the following:
class Post {
[Key]
public int Id {get;set;}
public DateTime CreationDate {get;set;}
[Required]
public virtual string Content {get;set;}
public virtual Thread RelatedThread {get;set;}
}
class Thread : Post {
public int ViewsCount {get;set;}
[NotMapped]
public override Thread RelatedThread {get;set;}
}
Because a thread consists of a post as startpost and have some additional attributes like the views. But the RelatedThread
attribute of the post will destroy my data-structure, so I want to overwrite it and let EF ignore it by using the NotMapped
attribute (see code above).
This does not work, I get the following error (translated):
The ignore-method cannot be used for the entity 'RelatedThread' in the model 'Thread' because he's inheriting from 'Post', in that the attribute is assigned. To exclude the attribute from the model, use the NotMapped attribute or the ignore-method for the base-type.
I also tried to exclude the attribute using fluent api in the OnModelCreating
method of my DbContext:
protected override void OnModelCreating(DbModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Thread>().Ignore(thread => thread.RelatedThread);
}
But nothing changes, I get the same exception again - Although I used both methods which are recommended in the exception. Why is this not working?