Steven Deam
Steven Deam

Reputation: 577

LINQ Results differ from SQL Server View

I have a LINQ Query that simply filters the results from a view that already exists on our SQL Server. The Problem that I am having is that the results coming in from the LINQ query are different than the results on the SQL server.

First I have created the EF connection through the wizard in VS. I create a context by a basic:

using(Entities context = new Entities())
            {

then the Linq Query is simply:

var Active = context.vwUniqueParts
.Where(a => a.HasOrders == true)
.ToList();

The problem is that I am getting repeated results in the returned data:

Where I would expect to see: Part1, Part2, Part3, Part4, Part5, Part6, Part7, Part8, Part9

I instead get: Part1, Part2, Part2, Part2, Part2, Part6, Part6, Part6, Part9

When looking at the results certain results will be repeated and then after a while it stops repeating. When it stops repeating the part that shows up is correct for it's place in the data set.

Upvotes: 0

Views: 100

Answers (1)

user3358344
user3358344

Reputation: 193

It sounds as though the primary key on the model does not match the database. If they differ, you'll find that the result set will return odd results such as you are seeing here.

Upvotes: 2

Related Questions