Easily create database tables from a logical model in .NET and VS

Background:

I started creating a logical database model for the ASP.NET MVC website. I used the visual designer for the Entity platform that comes with VS because I used it before.

But now I already have 33 classes, and I have not finished (including quite some inheritance and a lot of associations). I am afraid that for me it would be too complicated and time-consuming to manually set all table mappings and create database tables. I have no experience with this - I did it differently: classes from database tables, and it took me a long time to get it to work in a smaller project.

Question:

How can I easily and quickly create database tables for a logical model (class diagram) in .NET / VS? It would be great if it were possible automatically. I have never worked with the LinqToSQL visual designer, and there seem to be no links on the Internet to how to create database tables from LinqToSQL classes. Is it even possible? If there is no way to create database tables with an Entity map automatically - without having to specify table mappings?

And one question: if I use the LinqToSQL classes, will it make changes to the database every time properties change? Or is there some kind of caching?

+4
source share
3 answers

Entity structure has the concept of "First Model", which generates a database model from your model, hence the name.

You can read about it here: http://msdn.microsoft.com/en-us/data/ff830362

However, my personal favorite when it comes to object relational maps is NHibernate with the addition of Fluent NHibernate. They have a concept in which you work with a domain model, not a data model, and you use conventions to manage your mappings. This is pretty neat. You can start with some pretty good examples by looking at this code here: https://github.com/sharparchitecture/Northwind/tree/master/app

Linq2Sql is too limited for the case you are talking about. And he does not have the ability to generate data models from code. In fact, Linq2Sql works the other way around - it generates a set of classes from your data model, just as Entity Framework can.

Neither Linq 2 SQL nor Entity Framework commit anything until you explicitly decide to do so. They both have the concept of an object context that tracks all changes made. When you call Save, they convert these changes to SQL, which is then executed in the database.

+5
source

Like MikeEast, I had very good experience with Fluent NHibernate.

In my project, I use the Automapping function, which allows me to change my data model almost at will, and the database schema is automatically updated.

No SQL, no worries about foreign keys, etc. etc. etc. - I like it!

Free use of NHibernate Automapping

+1
source

Finally, I stuck to the Entity structure - table generation is really flat, as soon as I learned how to handle database connections ...

0
source

Source: https://habr.com/ru/post/1343255/


All Articles