Suppose that I have a database with 1 table named Products
. So, I go through the Db First approach and create an EF model in VS 2012 with pluralize and singularize
option.
So, the model creates a Product
entity for me, and default naming convention maps this entity to the dbo.Products
table.
Now I want to change this behavior. In fact I want to create a custom convention to map ProductModel
entity to the dbo.Products
table.
Is this possible?! If so, how?
Update: My goal to do it...
As you know, whenever you update your model from database, if it causes a change in your model, the auto-generated entities will be over written.
From the other hand, I want to add data annotation attributes to entity properties so that I can use them to shape my views and want to simply work with my DbContext like the following insert:
public ActionResult Create(Product product)
{
if (ModelState.IsValid)
{
db.Products.Add(product);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(product);
}
the problem is that my application analysis isn't completed and the database changes times to times. So, I need to update the model from the database and after that, all my attributes will removed.
So I decided to create a ProductModel
class and copy the Product
codes to it, and pass it the views as view model. Then, whene I want to query my db, I'll get an exception which says that the dbo.ProductModels
name is not exist in the db...
Thanks in advance