I’m new to ASP.NET MVC 3 with Entity Framework, and I’ve purchased a couple of books around this subject and have researched on this on a number of sites. But, there are still a couple of questions that are un-answered or unclear. Most of the examples from the books, and tutorials on the sites don’t cover end-to-end scenarios, and they cover a basic approach.
The following areas are where I’m quite unclear:
-
When you create a database first approach, with a normalised schema. How does this translate into the classes ? The steps that I had taken was 1) create the tables, then I added a ADO.NET Entity Data Model. From here, i chose to generate a data model from a database. There was no issues yet, all tables were generated as classes. From there, I selected “Add Code Generation Item” via the right click context menu. I then chose to add ADO.NET DbContext Generator. This create the classes etc.. for my models. From here should i manually edit the class files to produce a 1 to many relationship ?
-
With the classes that I have generated (see #1) can I manipulate these to ensure that I can add logic within the setting of the attribute (i.e settting a property, I have code with an if statement and if it is true it also updates secondary value. e.g if(myVar != “”){ myChangeVar = currentDate;)
-
Can I have multiple classes to a table with Entity Framework ? Almost creating different views etc…
Thanks
You never ever manually modify any auto generated code – that is key for working with code generators. Any change to EDMX will delete all your changes in generated code because generation tools work in simple approach: delete whole file content and create a new one.
If you need any special code directly inside generated classes you must
You can also need some specific code which is related to some class or some property. In such case: