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

编程入门 行业动态 更新时间:2024-10-23 15:19:22
本文介绍了如何从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创建表到现有数据库

本文发布于:2023-07-29 11:06:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1240133.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   datacontext

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!