开发者

How I Can use Linq Query count no. of record in query

var emailToProcess = 
    from a in db.EmailNotToProcess
    join b in EmailUids on a.ENTPUId equals b.Uid
    where a.ENTPUId != b.Uid
    select b;

Here EmailUids is a List and EmailUid is a struct inside the struct we have two option like

public int EmailId;
public s开发者_JAVA百科tring Uid;

this ..

so I am executing the query but I am not able to count the how much record in this query...

thanks....


You can use the Count() method:

var emailToProcess = from a in db.EmailNotToProcess
                     join b in EmailUids on a.ENTPUId equals b.Uid
                     where a.ENTPUId != b.Uid
                     select b;
int emailCount = emailToProcess.Count();


You are trying to join an SQL Table via Linq-SQL with an external List, which I dont think is supported


If there are only a handful of ID's in the List then you can use Contains. This will pass each integer to SQL as a parameter:

var emailToProcess = from a in db.EmailNotToProcess
                     where !EmailUids.Select(u => u.Uid).Contains(a.ENTPUId)
                     select b; 

int count = emailToProcess.Count(); 

NOTE:

If there are 1000's of IDs in EmailUids then you'll have to rethink your strategy. Either move the list of ID's into a SQL table (so LinqToSQL can perform the translation from LINQ to raw SQL) or you will have to pull back the entire rowset for EmailNotToProcess and then perform the join on the client.

It's hard to advise without knowing how much data you're dealing with in each table/list.


Maybe with a Contains:

var emailToProcess = 
    from mail in 
        (from a in db.EmailNotToProcess
         where EmailUids.Select(e => e.Uid).Contains(a.ENTPUI)
         select a).AsEnumerable()
    join b in EmailUids on mail.ENTPUId equals b.Uid
    where mail.ENTPUId != b.Uid
    select b;

int count = emailToProcess.Count();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜