如何在C#中获得以下结果 [英] How to get the following result in C#
本文介绍了如何在C#中获得以下结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有3个视图V1,V2,V3我将它们添加为我的Web应用程序中的实体。总共有login_name公共字段,我需要得到以下结果。
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
。 | .. | .. | 。
解决方案
根据视图中数据的组织方式,可能类似于SQL中的内容
< pre lang =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
或if你在LINQ中做的那么可能就像
var query =
来自 v1row 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
}
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.
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
. | .. | .. | .
解决方案
Depending how the data in the views is organized could be something like following in 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
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 }
这篇关于如何在C#中获得以下结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文