How should I model a database with Entity Framework? - asp.net-mvc-4

I'm just starting to use Entity Framework Designer. I would like to ask how should I create my Entity files. I would like to have like 10 tables and all of them will be linked to at least one other table by some row. Should I create just one file and put all my models there or create a separate file for each model.
I don't know if this is even a question but I could find my answer on Google. I didn't know how to define it actually... :D
So if you have any tips on how I should model my database that will be awesome. Also if you have any more information on when I should use different Entity files that will be useful too.
I have used MySQL designer in the past but in there as far as i can remember you just move the model into the designer and you can make relations. So I'm kinda keen into doing that (all models in one Entity File) but wanted to check with you first guys.

just try this plugin for VS http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d to generate your classes from existing db

Related

Missing EDMX file from inherited VB.Net Entity Framework 6.1 project

First of all I'm new to Entity Framework and have inherited a vb.net project. I'm trying to add an existing table to the model. The table is in the same database the model refers to.
I've read and watched lots and theoretically understand what I need to do but everyone speaks about right clicking on the emdx file and click on 'Update Model from Database'. This project doesn't have an emdx file. (hidden or otherwise)
So I'm confused. So I have one?
If not can anyone advise me on another way to update the model to add an already existing table please?
Thanks
I've read and watched lots and theoretically understand what I need to do but everyone speaks about right clicking on the emdx file and click on 'Update Model from Database'
That's just one approach to EF: "database first" where the database is designed and then the EF Model (in the form of a .edmx file) is part of the project (and then used to generate the code files for db context and entity types).
The other two approaches are "Model First" where the designer (or direct XML editing) is used to write the .edmx directly.
Finally – and this is what you might have – there is "Code First" where the DbContext derived type and entity types are written directly. Check the DbContext derived type and the entity types being hand written (or at least maintained).
For information on the different approaches the EF's documentation site includes introductory articles including a video about the different models.

Can the ASP.NET Entity Framework automatically generate data annotations?

My team is writing a large scale business website in ASP.NET MVC 4 using the database-first approach. Does anyone know if it's possible to have data annotations automatically generated based on the database schema? It seems redundant to have to manually write the "buddy" metadata classes containing the data annotations when the framework should be aware of a database column's properties and make these part of the POCO classes it generates. Any suggestions would be greatly appreciated!
Take a look at LINQ to SQL.
You can use it to create a .dbml file in a graphical editor by dragging the tables from the server explorer.
Here's the MSDN How to: Create LINQ to SQL Classes in a Web Project
1) The framework does a good job of extrapolating data annotation based on table structure, but they won't be perfect.
2) Sadly, when you reach a point when you want to customize more than the framework, you are stuck with Buddy classes. They're a bit tedious but so far the best method I've found for customizing data annotation.
3) All too often, I find myself gravitating toward custom classes and away from generated POCO's. The reason is usually the differences between storing and displaying. In entry screens
I will often break up phone #'s into 3 textboxes.
Lookups for foreign keys require select lists (often added to model).
Often I'll pass other values that may be relevant to my View functionality but not specific to the storage table (display fields, navigation / bread crumbs)
Use the Database First approach with the Entity Framework.
You can generate the entity model from an existing database using the entity data model wizard.
See http://msdn.microsoft.com/en-us/data/jj206878
#Kerezo covers pretty much exactly what you want to do here: Add Data Annotation To Entity Framework(Or Linq to SQL) generated class
It is not possible to auto generate the data annotations automatically.

Automate the creation of Partial Classes from an entity data model

If I create an entity data model using the using the model first approach and building my model from an existing database is there a way that I could then automate the creation of partial classes to then allow me to extend the model to fit my requirements. So for example were I to model the Northwind Database then, amongst others, entities would be created for 'Customer' and 'Order'. I would like to find a way to then have visual studio to build a set of partial classes for each of the entities and put them into separate files.
I have no idea if this is doable in the first place, or if it is what the best way to go about doing it would be. To that end I would welcome any suggestions and / or good basic examples of where to start learning how do to this sort of thing. Ideally any such examples would have content in vb as well as c#.
Many thanks

.NET Multiple Entity Models using Multiple DB's in the same VS2010 Project

Greetings everyone!
Here's the deal, I've got a site that has multiple languages, each language has its own MSSQL database. I tried to add an Entity Framework Data Model for each database, only to find that the partial classes are conflicting with the other EF Data Models. So the column "banner" from one Model conflicts with the column "banner from another Model. I'm trying to make this as universal as possible by not naming the columns differently but instead dynamically changing the Model I'm using when a specific language is selected.
Any ideas? I'd really appreciate the help!
Tom
If those DB have same schema, all you need is one model. Then based on user's language, connect to relevant DB.

Database Schema To Another Database Schema Converter

Is there anyway that I could generate database from one schema to another?
For example, I would like to run my application from oracle to sql server or from sql server to postgresql?
I'm looking for something that's free....
Also I would like to know if there's a schema initializer to go with it
thanks a lot
The best tool I found so far is to use Squirrel's DBCOPY plugin. It really does the job
This doesn't really fall under the "free" category, but if you already have the tools (Microsoft Visual Studio and appropriate .NET providers), it might be a possibility.
The idea is to generate a data model from one database in Visual Studio and then use the Model First functionality to go from the conceptual model to another database. The steps would be something like this:
In a VS2010 application, add a new item to the project: ADO.NET Entity Data Model
Choose your existing database the source for this new model and select the desired tables and click through the wizard.
After the model is created, make sure the conceptual model is visible (.edmx file). In the properties for the model, there should be a DDL Generation Template option. Change this to the desired target type. This is the really iffy part; I don't know how many providers support this, but a quick search seemed to turn up at least one for Postgres.
Right click on the model and choose Generate Database from Model. This should produce the DDL for the new database.
This certainly would not lend itself well to an automated process, but for a one-time process, it might be okay.