简体   繁体   English

如何使用graphdiff忽略属性?

[英]How to ignore property using graphdiff?

I'm using EF6 with graphdiff and EDMX and must ignore a property of a particular entity. 我正在使用带有graphdiff和EDMX的EF6,并且必须忽略特定实体的属性。

How should I do since even getting the property the insert or update always leave the NULL field? 我该怎么办,因为即使获取属性插入或更新总是留下NULL字段?

The way I was able to work around this while still benefiting from the ease of GraphDiff was as follows: 我能够解决这个问题的方式,同时仍然受益于GraphDiff的易用性如下:

  • Set your object equal to the GraphDiff method 将对象设置为等于GraphDiff方法
  • Set each property you wish to ignore to .IsModified = false 将要忽略的每个属性设置为.IsModified = false

(Example) (例)

  user = db.UpdateGraph(user, map => map
            .AssociatedCollection(u => u.UserRoles)
            .AssociatedCollection(u => u.Teams));

    db.Entry(user).Property(u => u.Password).IsModified = false;
    db.Entry(user).Property(u => u.Salt).IsModified = false;

    _context.SaveChanges();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM