I have tested the other tables in the model and they are working. However, I added two new tables and they are not in the model.
How do I ensure that a database table is part of the model?
OnModelCreating
is NOT called in this code.
The entity type AppToLeadRequestLine is not part of the model for the current context.
This exception is thrown when adding an item to the table.
public void Add<T>(T obj) where T : class
{
Set<T>().Add(obj);
}
I added both of these tables to the database.
After adding these two tables to the database I generated them in the model by using Update Model from Database
, and both tables appear in the model.
When I look at the table mapping they appear to be mapped to the correct POCO. I'm not 100% sure about this.
The classes look like this:
OnModelCreating
is not called -- as you pointed out -- so I can be certain that you are using a Model-First approach (and not Code-First). In this case, you are responsible for all of the mapping. Here is a good article on the topic.
It appears that RequestId
is a foreign key to the AppToLeadRequest
class -- if this is the case, you must declare the public virtual
statements in both classes yourself.
For example -- at the bottom of the AppToLeadRequest
class, it should contain:
public virtual ICollection<AppToLeadRequestLine> AppToLeadRequestLines { get; set; }
and, at the bottom of the AppToLeadRequestLine
class, it should contain:
public virtual AppToLeadRequest AppToLeadRequest { get; set; }
I would also change RequestId
to AppToLeadRequestId
to follow a <class name>Id
format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With