2

I have a really weird issue.

I have this query:

var systemAppEntityViewModelFieldCustom_SecurityByUserList = (from t in coreEntityModel.SystemAppEntityViewModelFieldCustom_SecurityByUser
                where (t.SystemAppUserID == CurrentSystemAppUser.SystemAppUserID)
                    && (t.SystemCultureID == CurrentSystemAppUser.SystemCultureID)
                select t).ToList();

Producing these values for the field "CustomFilterID":

enter image description here

As you can see, "CustomFilterID" = 1 for all 4 items, but when i check SQLProfiler and a run the result query in SQLServer, i get this:

enter image description here

A variation of "CustomFilterID" = 1 AND 2.

Any idea why LINQ will produce all 4 items with a "CustomFilterID" = 1?

8
  • Which one is the right one? Commented May 21, 2013 at 8:22
  • @FrancescoDeLisi SQL results. Commented May 21, 2013 at 8:23
  • 1
    I have had this problem when the primary key on the model is not setup correctly, check that first. Commented May 21, 2013 at 8:33
  • Can you list the values of coreEntityModel.SystemAppEntityViewModelFieldCustom_SecurityByUser? It looks weird. Commented May 21, 2013 at 8:36
  • Perhaps you need to refresh your context? Commented May 21, 2013 at 8:52

1 Answer 1

2

Found the issue. My View was not selecting the PK column of the table and by adding the PK column of the table to the select list of the View, it produced the correct results.

Sign up to request clarification or add additional context in comments.

1 Comment

That's exactly one of the "thorny" issues with selecting from views - even if you don't want to display it, you need to include the underlying table's PK to make EF work properly with views

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.