1

I am using entity model.i updated one view called SalesDetialView.

In salesdetialview i have 3 entity keys. There are 1.Type 2.No, 3.Custmor enter image description here

SQL : I am using this query(i am printing just 5 columns )

select Customer,Type,No,Salesperson,amount from SalesDetailView enter image description here

But through entity model i am not getting duplicate values(No).see this below screen enter image description here

Now i have doubt why it is not showing duplicate values. Any thing related for entity keys or any thing. Please suggest me where i am doing mistake.

1
  • What query does EF emit? Commented Oct 27, 2012 at 23:51

2 Answers 2

1

If multiple rows share the same value in the primary column(s), only the first of these seems to be retrieved from the database and copied into these other rows. For instance, if a set has 2 columns, with the first being marked as the primary column, and

the correct result should be:

A, 1
A, 2
B, 4
B, 6
B, 7
C, 5


The actual result in code with Entity Framework would become:


A, 1
A, 1
B, 4
B, 4
B, 4
C, 5

When including a view in your Entity Model, the model seems to simply use the first not-nullable columns as primary key (as all columns used in the primary key should be non-nullable). To fix the problem, make sure that the primary key columns are chosen correctly. If you cannot create the correct primary key because of null-values or simply not having set of columns that differs for each row, try adding a column to your view that always contains a unique value for each row. After you add it, make sure it is set as the primary key in your Entity Model.

If I would set both rows to be the Primary Columns in the above example, I would get the desired result.

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

1 Comment

using primary column we are not showing duplicates. But in my view it does not have pk columns in it. when run the quary in sql it is showing all rows. But not through entity model.
1

you can solve it by changing the merge option of the ObjectSet. Example:

 using (TargetDBDataContext db = new TargetDBDataContext())
        {
            db.SomeView.MergeOption = System.Data.Objects.MergeOption.NoTracking;
            return db. SomeView.ToList();
        }

Comments

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.