Domanda

I have an entity model of an Oracle data source over which I have no control. Using this model I query a particular view to see get all volume price breaks for a given product:

enter image description here

As you can see, this view has no primary key. Here is the LINQ I am using:

 var db = GetOracleDataContext();
 var result = db.ITEMPRICEBREAKS_V.Where(p => p.STOCKNO == stockId).ToList();

This works to some degree, but instead of returning four distinct records with their own quantities and pricing, it returns four identical records, each with the pricing and quantities of the first record ($4800, 0, 2).

I have no control over this view. Is there another way I can structure my LINQ query so that I can get the four distinct values?

È stato utile?

Soluzione

Select only the fields you care about and use Distinct(). For example:

var result = db.ITEMPRICEBREAKS_V
    .Where(p => p.STOCKNO == stockId)
    .Select(p => p.Price)
    .Distinct()
    .ToList();

However, I'd strongly recommend, along with the other commenters, that you get a primary key involved.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top