0
我有一個控制器方法,它在我的asp.net mvc項目中使用edmx模型,該項目用於從SQL數據庫中的View中獲取數據。目前,我只對該表的兩列感興趣。我可以使用我的實體類和簡單的Linq語句來獲取數據,以將返回的數據存儲到列表中。我想要做的是循環遍歷列表,並檢查這兩列的數據都填充到哪裏(值可以是null或填充數據),並返回給我一個真值的行。下面是我的方法的代碼片段:C#控制器方法實體模型
public ActionResult GetCurrentState()
{
// create the entity object
ALCS4Entities entities = new ALCS4Entities();
// Get the InterConnectPortGidAB column data
var checkInterConnectPorts = (from icp in entities.LogicalConnectionEndToEnd_v
select new
{
InterconnectPortGidA = icp.InterconnectPortGidA,
InterconnectPortGidB = icp.InterconnectPortGidB
}).ToList();
return Json(new { interConnectPortGidABList = checkInterConnectPorts}, JsonRequestBehavior.AllowGet);
}
我錯過了什麼嗎? 'from icp in entities.LogicalConnectionEndToEnd_v where InterconnectPortGidA!= null && InterconnectPortGidB!= null' –
第一個評論者說什麼,我不會在查詢結果周圍創建一個匿名對象。我只是發送結果 --return Json(checkInterConnectPorts,JsonRequestBehavior.AllowGet); – Fran
@ freedomn-m,我如何接受你的評論作爲答案? – DeeTee