Does anyone know how to change the mapped db table for an entity in EF4 (entity framework 4)?
Later edit: I think i've found the place where the table names are defined, in the model browser. But their names are readonly, so it's not possible to edit them using the designer. Also, there's no reference (from what i've searched) to the table name in the xml schema.
If you just need to change the name of the table you can:
<EntitySet Name="Customers" EntityType="ExampleModel.Store.Customers" Schema="dbo" />
. Table="MyTableName"
attribute. <EntitySet Name="Customers" EntityType="ExampleModel.Store.Customers" Schema="dbo" Table="MyTableName" />
Here is a complete CSDL, SSDL, MSL specification.
Hope that helps.
An alternative solution would be to override a method in your DbContext
class.
public class MyDbContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Product>().ToTable("DB_PRODUCTS_TBL");
// otherwise EF assumes the table is called "Products"
}
}
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