views:

42

answers:

1

Hi. 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 ?

A: 

Hi. 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.

Brian J. Hakim