我计划加入2个表,并获得语言列的不同值。我应该如何在Linq实现这一目标?我尝试添加'组'但没有运气。此外,我想与r不同的语言值一起选择s值。
我的代码:
public ActionResult QuestionLink(int Survey_ID)
{
var query = from r in db.SURV_Question_Ext_Model
join s in db.SURV_Question_Model
on r.Qext_Question_ID equals s.Question_ID
where s.Question_Survey_ID == Survey_ID
group r.language << this is not work **
select r;
return PartialView(query.ToList());
}
答案 0 :(得分:2)
这就是MoreLinq中<button onclick="getLocation()">Try It</button>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
所称的内容。但是,如果该方法适用于<script type="text/javascript">
var adjustementType = { -1:'Rate Decrease', 1: 'Rate Increase' };
</script>
,那么您就无法在EF查询中使用它。但是你可以使用相同的方法:
DistinctBy
但我想知道这是否真的是你想要的。结果取决于数据库碰巧返回的语言顺序。我认为您应该为特定语言添加谓词并删除分组:
IEnumerable
答案 1 :(得分:1)
你可以这样做:
var query = from r in db.SURV_Question_Ext_Model
join s in db.SURV_Question_Model
on r.Qext_Question_ID equals s.Question_ID
where s.Question_Survey_ID == Survey_ID
group new {r, s} by r.language into rg
select rg.Key;