Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Join two tables and sum a certain colum with linq to sql c#

$
0
0

Greetings

I want to get 0 if sum result is null using Linq toSQL and C#.

Can anyone please help with this query?

internal decimal GetItemPurchasedByDate(linqToSqlDataContext db, int itemId, DateTime firstDay, DateTime lastDay)
    {
        var count = (from pl in db.tblPurchaseLines
                    join p in db.tblPurchases on pl.PurchaseId equals p.PurchaseId
                    where pl.ItemId == itemId && p.PurchaseDate >= firstDay && p.PurchaseDate < lastDay
                    select pl.Qty).Sum();

        return count;
    }


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>