简体   繁体   English

使用GraphDiff的条件映射

[英]Conditional mapping using GraphDiff

I am having an issue with GraphDiff whilst saving some data and I just need some one to confirm if this is possible. 我在保存一些数据时遇到了GraphDiff的问题,我只需要一些就可以确认是否可行。

I will provide an example of what is going on: 我将提供一个示例,说明发生了什么:

Firstly, I am using VS2017 (latest revision) EF 6, Automapper and GraphDiff. 首先,我正在使用VS2017(最新版本)EF 6,Automapper和GraphDiff。

I have a table which contains the following data. 我有一个包含以下数据的表。

表数据

As you can see this lists data for a ParcelId of 5023, the only difference is the IsAcquired and IsCurrent flags. 如您所见,它列出了ParcelId为5023的数据,唯一的区别是IsAcquired和IsCurrent标志。

I am not going into the code that updates the data with the IsCurrent flag set to true as it is very complicated, but in essence, a screen allows users to enter values, that on saving sets the records in the second list from IsCurrent to False and inserts Three new records that have new values and has the IsCurrent set to True. 由于复杂,我不会进入将IsCurrent标志设置为true来更新数据的代码,但从本质上讲,屏幕允许用户输入值,保存时会将第二个列表中的记录从IsCurrent设置为False。并插入三个具有新值且IsCurrent设置为True的新记录。 This provides us the ability to undo these records. 这使我们能够撤消这些记录。

Now, I have differnt screen that enables you to edit the main data, or in other words the data from the first grid. 现在,我有一个不同的屏幕,使您可以编辑主数据,或者换句话说,来自第一个网格的数据。

This is using GrphDiff to update the data. 这是使用GrphDiff更新数据。 The data that is in the second grid is NOT recovered for this edit, but on saving the GraphDiff opertaion is seeing that the data is different and overwriting in. 此编辑不会恢复第二个网格中的数据,但是在保存GraphDiff操作时会看到该数据不同并被覆盖。

dbContext.UpdateGraph(a,map=>map.OwnedCollection(x => x.ParcelRight);

I need it to ingnore the records that an IsCurrent equals true and only update records that have IsAcquired = true. 我需要它来忽略IsCurrent等于true的记录,并且仅更新IsAcquired = true的记录。

I tried: 我试过了:

dbContext.UpdateGraph(a,map=>map.OwnedCollection(x => x.ParcelRight
                    .Where(r => r.IsAcquired == true).ToList());

but it did not work. 但它没有用。

I found the following which sort of implies that it cannot be done. 我发现以下暗示它无法完成的事情。

Research 研究

多亏了所有这些内容,但看起来这可能导致GraphDiff问题,因此我已更改此更新的代码,以使用更传统的Linq to Entites解决方案。

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

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