且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从datacontext创建表到现有数据库

更新时间:2023-02-03 16:53:32

如果你正在使用Entity Framework,谷歌进行Code First Migrations。



如果您只使用System.Data.Linq命名空间中的直接类,则必须执行SQL查询以自行创建表。

您好请通过此链接清除您的概念。请参阅此链接中的第2部分以解决您的疑问。



如何在C Sharp中使用LINQ to SQL(带图片) - wikiHow [ ^ ]


I have a DataContext and I have a name of existing database
I want to create all tables that DataContext contains to the database

What I have tried:

I have created a new database from the DataContext but I want to do that to an exist database

 DataContext db =new DataContext("Data Source=localhost\\sqlexpress;Initial Catalog=db;Integrated Security=True");
db.CreateDatabase();

If you're using Entity Framework, Google for "Code First Migrations".

If you're using just the straight classes from the System.Data.Linq namespace, you have to execute the SQL queries to create the tables yourself.


Hi please go through this link to clear your concept. See Part 2 in this link to solve your query.

How to Use LINQ to SQL in C Sharp (with Pictures) - wikiHow[^]