Skip to content
January 14, 2011 / windperson

.net 4.0 Entity Framework的一些bug

  1. 使用GUID當資料表的Primary Key時,要把該欄位在資料表設計時,設定成自動產生(有預設值,如newid()newsequentialid()),否則,讓Entity Framework來產生該欄位的話,會每次insert一樣的GUID值,於是DB就會回報insert資料失敗。
  2. Visual Studio 2010的Entity Designer有個很討厭的bug (理論上sp1會修掉):原本在上述的Entity設計和使用情形下,必須在Designer裡設定該使用GUID當Primary Key欄位的”StoreGeneratedPattern”設定成Identity,但實際上designer在寫入.dbml檔時,只有在CSDL層加上annotation:StoreGeneratedPattern="Identity",而沒有在 SSDL層對於對應資料庫實際上Primarky Key欄位的<Property>這個tag加上正確的StoreGeneratedPattern="Identity"這個attribute,必須自己手動把.dbml檔用XML Editor的方式開啟並修改;所以,當每次用designer對.dbml檔做修改後,都必須自行修正該SSDL層錯誤。

reference:http://leedumond.com/blog/using-a-guid-as-an-entitykey-in-entity-framework-4/

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: