如何从datacontext创建表到现有数据库 [英] How to create tables from datacontext to an existing database

查看:129
本文介绍了如何从datacontext创建表到现有数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataContext,我有一个现有数据库的名称

我想创建DataContext包含在数据库中的所有表



我尝试了什么:



我已经从DataContext创建了一个新数据库,但我想对现有数据库执行此操作/>


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

解决方案

如果你正在使用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[^]


这篇关于如何从datacontext创建表到现有数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆