开发者

RIA Services / EF. Changes to bool field in a derived class are not saving to database

We are using EF with RIA services. A simple application. Load a list of items, browse/edit/save. The problem is that some of the changes are not persisting to the db.

I have a model with the following

Person
   ...
   string Name
   bool IsActive


Customer : Person
   ...
   string Address
   bool IsLocal

Changes made to a Person save correctly.

When changing a Customer, if I change the IsLocal value to true, it saves correctly. If I change it to false, the change is not persisted to the database.

  1. Boiler plate generated code, no customizations
  2. No error messages. As far as the submit op is concerned, all went well.
  3. Changes to Address save correctly
    • If I change the Address and set IsLocal, both save correctly.
    • If I change the Address and clear IsLocal, the address saves but IsLocal stays set.
  4. Changes to IsActive (in Person) always save correctly, whether clearing or setting.
  5. I have recreated the problem in another solution with different tables.
    • Seems to be the same problem, cannot clear bool/bit field in a derived class.

Any help开发者_开发知识库 that people can offer would be appreciated.

Thanks,

Alan.


Ok, I got a solution that is working for me...

I replaced the generated code for the Update method from:

this.ChangeSet.AttachAsModified( entity, this.ChangeSet.GetOriginal( entity ) );

for

this.ChangeSet.Attach( entity );
this.ObjectContext.ChangeObjectState( entity, EntityState.Modified );

Hope this helps!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜