CTP5 Guid-PK-DatabaseGenerationOption.None在模型中首先似乎不起作用。 [英] CTP5 Guid-PK-DatabaseGenerationOption.None in model first does not seem to work.

查看:63
本文介绍了CTP5 Guid-PK-DatabaseGenerationOption.None在模型中首先似乎不起作用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个类似于  http://blogs.msdn.com/b/adonet/archive/2010/12/14/ef-feature-ctp5-model-amp-database-first-with -dbcontext.aspx  除了
我想使用Guid而不是Int作为我的主键。我想在代码中设置我的初始主键值,而不是生成数据库。似乎是edmx的"StoreGeneratedPattern"不遵守。知道任何工作吗?我尝试了很多东西,包括
DataAnnotations。 

I created a sample similar to http://blogs.msdn.com/b/adonet/archive/2010/12/14/ef-feature-ctp5-model-amp-database-first-with-dbcontext.aspx except I wanted to use a Guid as opposed to Int for my primary key. I want to set my initial primary key value in code as opposed to database generated. Seems the edmx's "StoreGeneratedPattern" is not obeyed. Know of any work arounds? I have tried many things including DataAnnotations. 

 

推荐答案

汉克,

 

默认情况下使用Database First方法时,主键将被视为数据库生成(&ndquo; Identity”)基于数据库中定义的
键是否为Identity密钥。  我相信您可以在实体设计器中更改此内容。 
但是,如果这样做,事情可能无法正常工作,因为数据库将在插入时生成密钥,但EF将假定您提供的密钥是正确的,并且不会使用新的密钥更新实体生成密钥。

When using the Database First approach by default the primary key will be treated as database-generated (“Identity”) based on whether or not the key defined in the database is an Identity key or not.  I believe you can change this in the Entity Designer.  However, if you do so things may not work correctly since the database will be generating the key on insertion, but EF will assume that the key you provide is correct and will not update the entity with the newly generated key.

  ;

For数据库首先,您最好的办法是更改数据库中的列,使其不是Identity列,然后生成/更新您的实体。

 

谢谢,

Arthur


这篇关于CTP5 Guid-PK-DatabaseGenerationOption.None在模型中首先似乎不起作用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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