English 中文(简体)
EF4.1 代码一 - 增加一列
原标题:EF 4.1 Code First - add column

我已設定了我的数据库, 我想在模型中新增一个字段, 在表格中新增一个列, 是否有办法在不丢失全部数据的情况下做到这一点? 通常, 如果您删除 DB, 它将会自动重建所有数据, 但我不想丢失数据。 我将 SQL 服务器2008 用作数据库 。

最佳回答

您需要使用 EF 迁移来在数据库中添加新栏目。 您可以阅读更多关于 EF 迁移 < a href="http://msdn.microsoft.com/ en- US/ data/jj554735" rel = "noreferr" >这里 和 < a href="http://msdn.microsoft.com/ en- US/ data/jj591621, rel="noreferr"。

问题回答

如果您首先使用代码, 我总是在这样的情况下手工将列添加到数据库中。 不幸的是, 没有简单的方法可以自动使用代码一的增量模式更新 。

例如,《EF Code First s 自己的差错之一甚至指定人工更新为最佳选择:

支持“ 您的上下文” 的模型自数据库创建以来已经改变。 要么是手动删除/ 更新数据库, 要么是用 IDatabase Intializer 来调用数据库 SetIntializer 。 例如, DroftCreateDatabaseIfModelChanges 战略将自动删除和重新创建数据库, 并选用新数据进行种子 。



上一篇:
下一篇:


相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签