Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I written below query in linq and want distnict record form item list but it's give me duplicate record also, Please help, Your help will too much appreciated!!!

XML
var skus = (from sku in multiviewcontext.GetTable<Ignify.Framework.Data.Tables.SKU>()
                      join product in multiviewcontext.GetTable<Ignify.Framework.Data.Tables.Product>() on sku.ProductId equals product.ProductId
                      join itempricelist in multiviewcontext.GetTable<Ignify.Framework.Data.Tables.PMItemPriceList_AX>() on product.Code equals itempricelist.ITEMRELATION
                      where
                      RequestedproductMasterIds.Contains(product.Code) &&
                      sku.CSRInformation == projectVariantId &&
                      itempricelist.CONFIGID == projectVariantId &&
                      itempricelist.ACCOUNTRELATION == priceGroupId
                      && sku.Visible==true// &&sku.StockQty>0
                      select new
                      {
                          sku.StockQty,
                          sku.Code,
                          itempricelist.AMOUNT,
                          itempricelist.TODATE,
                          productcode = itempricelist.ITEMRELATION,
                          sku.CSRInformation
                      }).Distinct().OrderByDescending(x=>x.TODATE);
Posted
Updated 30-Jun-14 4:32am

1 solution

well it's hard to say...

but i think that using a single query like yours is even harder.

try to split your query like that

C#
var skus = from sku in multiviewcontext.GetTable<Ignify.Framework.Data.Tables.SKU>()
           where sku.CSRInformation == projectVariantId
           where sku.Visible
           select sku;

var products = from product in multiviewcontext.GetTable<Ignify.Framework.Data.Tables.Product>()
               where RequestedproductMasterIds.Contains(product.Code)
               select product;

var itempricelists = from itempricelist in multiviewcontext.GetTable<Ignify.Framework.Data.Tables.PMItemPriceList_AX>()
                     where itempricelist.CONFIGID == projectVariantId
                     where itempricelist.ACCOUNTRELATION == priceGroupId
                     select itempricelist;

var result = from sku in skus
             join product in products on sku.ProductId equals product.ProductId
             join itempricelist in itempricelists on product.Code equals itempricelist.ITEMRELATION
             select new {sku, product, itempricelist};


and debug every "part" to find the duplicates.
 
Share this answer
 
Comments
raneshtiwari 1-Jul-14 1:47am    
Thanks Katanakensei for providing me a solution but I am not sure split query can generate a better result, I am searching another way to fix this issue, I am trying to fix this issue using where condition or group some fields.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900