开发者

RIA EntityQuery duplicating rows where one of the values matches

In my app I perform an entityquery. If I use SQL profiler, catch the SQL query that is generated, and run it manually, it gives the results I expect. For instance

Val     Date
68  2011-05-31 00:00:00.000
48  2011-05-30 00:00:00.000
92  2011-05-29 00:00:00.000
52  2011-05-28 00:00:00.000
32  2011-05-27 00:00:00.000
32  2011-05-26 00:00:00.000
52  2011-05-25 00:00:00.000
81  2011-05-24 00:00:00.000

If I stick a breakpoint in my code and look at what the LoadOperation.Entities contains, I notice that when the 'Val' figure for an entry has already appeared (I.E like 52 above), then the LoadOperation.Entities collection uses the data from the previous entry (with a value of 52), rather than the actual date. So in the data above, my LoadOperation.Entities looks like (note that dates are now repeated, seemingly because the 'Vals' have occurred previously)

68  2011-05-31 00:00:00.000
48  2011-05-30 00:00:00.000
92  2011-05-29 00:00:00.000
52  2011-05-28 00:00:00.000
32  2011-05-27 00:00:00.000
32  2011-05-27 00:00:00.000
52  开发者_如何学Go2011-05-28 00:00:00.000
81  2011-05-24 00:00:00.000

Does anyone know why this is happening?

My EntityQuery looks like

    var appDataQuery = context.GetVwKeyDatasQuery().Where(d => d.KPIDate <= OverViewDate && d.GELID == GelID && d.ClockworkID == ClockWorkID).OrderByDescending(d => d.KPIDate);

And this generates the correct T-SQL, which when executed in SQL Query Analyzer returns the correct values.

The rest of the code is

    LoadOperation lo = context.Load<vwKeyData>(appDataQuery);
    lo.Completed += new EventHandler(LoadOperation_Completed);

The EventHandler is

    public void LoadOperation_Completed(object sender, EventArgs e)
    {
    LoadOperation<vwKeyData> histResults = sender as LoadOperation<vwKeyData>;
    int _count = 0;
    foreach (vwKeyData v in histResults.Entities)
    {.......

By this point histResults.Entities is already incorrect. Any help would be appreciated as this is screwing up some charting stuff i'm working on.

Thanks

M


You need to set the following.

context.vwKeyData.MergeOption = MergeOption.OverwriteChanges;

OverwriteChanges will make sure that the data is always loaded from the datasource. This should help sort our your problem.


Answer as above. Each column that is required to uniquely idenitfy a row, should be set as an Entity Key in the model.

(Right click the column in the model designer and select Entity Key).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜