开发者

Concurrency check fails with hierarchical data EF 4.0

I got a problem with Entity Framework 4.0

I have a hierarchical table Category: Id, Name, ParentCategory_Id, timestamp

The "timestamp" field is marked as "Concurrency Mode" 开发者_开发技巧= "Fixed"

And I'm using Self-Tracking Entity "Category" to manage Category entity in my MVC application.

The situation:

  1. I create STE "NewCategory",
  2. set field Name='bla-bla'
  3. create new STE "ParentCategory" like this: var ParentCategory = new Category{Id=45}; ParentCategory.MarkAsUnchanged(); NewCategory.Parent = ParentCategory;
  4. Call ApplyChanges() method in my STE Context and call SaveChanges()
  5. The Query is "Update Category set Name=...." !!!!!!

If I do NewCategory.Parent = null OR set "Concurrncy Mode" = "Node" in model scheme everything works FINE.

How to use hierarchical data with concurrency check ?


I solved this problem. The solution is that the EF4.0 could manage theese situations only if you will use FK Assotiation properties.

In this sample the right way to do:

1)Create self assotiation in Category entity in edmx model. In "Referential Constraint" create link with parent entity via ParentCategory_Id property.

2) Create new instance of Category STE.

3) Set relation:

NewCategory.ParentCategory_Id = 45;

4) ApplyChanges, SaveChanges.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜