Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 views V1,V2,V3 i added them as entities in my web application. There is "login_name" common field in all and i need to get the below result.

C#
LoginName  | SoldCount[V1field]|PurchasedCount[V2 field]|ThroughCount[V3 Field]
==================================================================================
abcd       |  20               | 12                     | 0
gefg       |  10               | 00                     | 3
sdff       |  00               | 36                     | 1
ewre       |  30               | 00                     | 0
.          |  ..               | ..                     | .
Posted
Updated 25-Jan-15 0:39am
v2
Comments
Kornfeld Eliyahu Peter 25-Jan-15 6:42am    
Why not use SQL with JOIN to build a 4th view? SQL after all is much better with data than LINQ...

1 solution

Depending how the data in the views is organized could be something like following in SQL
SQL
SELECT v1.LoginName,
       v1.SoldCount,
       v2.PurchaseCount,
       v3.ThroughCount
FROM v1
     inner join v2 on v1.LoginName = v2.LoginName
     inner join v3 on v1.LoginName = v3.LoginName

or if you're doing it in LINQ then perhaps something like
C#
var query =
    from v1row in v1
    join v2row in v2 on v1row.LoginName equals v2row.LoginName
    join v3row in v3 on v1row.LoginName equals v3row.LoginName
    select new {
       LoginName = v1row.LoginName,
       SoldCount = v1row.SoldCount,
       PurchaseCount = v2row.PurchaseCount,
       ThroughCount = v3row.ThroughCount
    }
 
Share this answer
 
Comments
shaprpuff 25-Jan-15 7:00am    
ERROR, DbExpressionBinding requires an input expression with a collection ResultType.
Parameter name: input

i need to count,

LoginName = v1row.LoginName,
SoldCount = v1row.SoldCount.Count(),
PurchaseCount = v2row.PurchaseCount.Count(),
ThroughCount = v3row.ThroughCount.Count()
Wendelius 25-Jan-15 7:16am    
If you need to do the counting in LINQ then you need to use GROUP BY clause. Have a look at How to: Group Query Results[^]
shaprpuff 26-Jan-15 1:48am    
still not get result
Wendelius 26-Jan-15 8:34am    
Can you post what your code currently looks like
shaprpuff 27-Jan-15 0:41am    
i have tried the same,

var query =
from v1row in v1
join v2row in v2 on v1row.LoginName equals v2row.LoginName
join v3row in v3 on v1row.LoginName equals v3row.LoginName
select new {
LoginName = v1row.LoginName,
SoldCount = v1row.SoldCount.COunt(),
PurchaseCount = v2row.PurchaseCount.Count(),
ThroughCount = v3row.ThroughCount.Count()
}

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