Error validating the default for column rowguid

Jon Smith looks at what tools there are in Microsoft's Entity Framework's Data Access technology that can deal with these requirements.

error validating the default for column rowguid-32error validating the default for column rowguid-41

The aim is to show how you can use EF with pre-existing databases, including ones that need direct access to T-SQL commands and/or Stored Procedures.

Entity Framework has a well-documented approach, called reverse engineering, to create the EF Entity Classes and from an existing database.

This produces data classes with various Data Annotations to set some of the properties, such as string length and nullablity (see the example below built around the Customer Table), plus a This does a good job of building the classes.

Entity Framework 6 has a number of features to make it fairly straightforward to work with existing databases.

In this article I’ll detail those steps that I needed to take on the EF side, in order to build a fully featured web application to work with the Adventure Works database.

I’ll actually use the Adventure Works LT2012 database, which is a cut-down version of the larger Adventure Works OLTP database. NET MVC5 (MVC) with the propriety Kendo UI package for the UI/presentation layer, which I cover in the next article.

At the end, I also mention some other techniques that I didn’t need for Adventure Works, but I have needed on other databases.

UNIQUEIDENTIFIER做主键(Primary Key)是一件很方便的事情,在数据合并等操作中有不可替代的优势但是由于普通的GUID的分散性使得如果主键加上聚集索引(Clustered Index)会导致在插入记录时效率大大降低SQL SERVER 2005中新增了一个NEWSEQUENTIALID的函数,MSDN的解释是:在指定计算机上创建大于先前通过该函数生成的任何 GUID 的 GUID。NEWSEQUENTIALID() 不能在查询中引用。您可以使用 NEWSEQUENTIALID() 生成 GUID 以减少叶级别索引上的页争用。但是使用NEWSEQUENTIALID却不是那么一帆风顺1.

如何获得生成的GUID如果生成的GUID所在字段做为外键要被其他表使用,我们就需要得到这个生成的值通常,PK是一个IDENTITY字段,我们可以在INSERT之后执行 SELECT SCOPE_IDENTITY()来获得新生成的ID但是由于NEWSEQUENTIALID()不是一个INDETITY类型,这个办法是做不到了,而他本身又只能在默认值中使用,不可以事先SELECT好再插入,那么我们如何得到呢?有以下两种方法: 2. 如何设定DEFAULT VALUE为NEWSEQUENTIALID()通过UI的方式设定默认值时,由于SQL SERVER 2005的BUG(即使是SP2也没有解决),导致我们设置了默认值为NEWSEQUENTIALID()保存时会出现以下错误:Warning were encountered during the pre-save validation process, and might result in a failure during save.

Pre-existing SQL databases, particularly if complex, can often pose problems for software developers who are creating a new application.

The data may be in a format that makes it hard to access or update, and may include functions and procedures.

206 Comments

  1. Where you live is not a matter, you can find and meet an Asian single online.

Comments are closed.