I am new to entity framework and started playing around with it. I am trying to use my usual structure that consists of a Core
project that has raw properties. DataAccess
extends core classes and adds any additional db specific property and the DBContext
in this case. Business
extends DataAccess
and has all business logic. Finally, a Models
project where multiple models may extend each business class for different purposes.
My class in Core
is something like this:
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
}
My DataAcceess
got a context class like this:
public class MyContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
}
And my Business
got this:
public class Blog : DataAccess.Blog
{
public void Add()
{
using (var db = new MyContext())
{
db.Blogs.Add(this);
db.SaveChanges();
}
}
}
Finally my Models
contains:
public class BlogModel : Business.Blog {}
Now I get an error that the entity type BlogModel
doesn't exist. The table's name is Blog not BlogModel. I have tried the following:
- Adding
[Table("Blog")]
in DataAccess, Business and Model - casting this as
(Blog)this
. The type still stays the same - Creating a property
Blog Current => this
trying to change it's type.
Update: happens even when the model is named Blog