简体   繁体   English

使用LINQ to SQL在现有数据库中创建表

[英]Create a table in an existing DB with LINQ to SQL

I have a SQL Express 2008 DB that has gone live. 我有一个已经上线的SQL Express 2008数据库。 I'd like to create a new table in that database without deleting all the existing data in the live DB. 我想在该数据库中创建一个新表而不删除实时DB中的所有现有数据。 I created an entity class for the new table and a separate data-context. 我为新表创建了一个实体类,并创建了一个单独的数据上下文。

What is the best way for me to add the new table using LINQ to SQL 使用LINQ to SQL添加新表的最佳方法是什么

Thanks... 谢谢...

That's not Linq To Sql's role in your architecture. 这不是Linq To Sql在您的架构中的角色。 You need to create the tables prior to deploying your new version of your data model. 您需要在部署新版本的数据模型之前创建表。

You can either manually update your db w/ direct SQL commands against it, or you can package it w/ the deployment (eg via continuous integration scripts or something like Migrator.NET) 您可以手动更新db w / direct SQL命令,也可以将其与部署打包(例如,通过持续集成脚本或类似Migrator.NET)

In the new Linq to Entity which shipped with Visual Studio 2010 there is easy way to create Database table from Model you built. 在随Visual Studio 2010提供的新Linq to Entity中,可以轻松地从您构建的Model中创建Database表。

here is the Example : Create a Database using Model-First 这是示例:使用Model-First创建数据库

为什么不直接执行SQL语句,比如create table [mytable] ...

Why you add unmapped-entities to diagram? 为什么要将未映射的实体添加到图表中? I think, first you have to create tables after map entities. 我想,首先你必须在map实体之后创建表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM