We have existing POCO model classes and an existing DB. The OO model classes and relational DB tables don't map directly to each other.
How do I use Entity Framework to map these? All of the tutorials I have seen are either Code First (which goes and generates new DB tables), Model first (which generates new DB tables and POCOs) and DB First (which generates new POCOs).
I want none of these! I want to map between existing POCOs and DB tables. What's the best way of doing this? Can I use the visual designer, or do I have to do it in code?
Create mappings which map your entities to database structure (I suggest to use fluent mappings). Then just disable database generation:
Database.SetInitializer<YourContext>(null);
and provide connection string to existing database:
public class YourContext : DbContext
{
public DatabaseContext(string connectionStringName)
: base(connectionStringName)
{
}
}
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