我想通過EF linq查詢從域對象收集一個值。但我得到一個錯誤,請問可以幫我糾正一下。實體框架中的Linq查詢錯誤
public String[] ReturnPatientIDs(int CounsellingRoomID)
{
var messageObject = this.context.CounsellingMessages.Where(c => c.CounsellingRoomID == CounsellingRoomID).Distinct();
String[] PatientIDs = new String[messageObject.Count()];
for (int k = 0; k < PatientIDs.Length; k++)
{
PatientIDs[k] = messageObject.ElementAt(k).Chatname;
}
return PatientIDs;
}
LINQ to Entities does not recognize the method 'Me.Domain.General.CounsellingMessage ElementAt[CounsellingMessage](System.Linq.IQueryable`1[Me.Domain.General.CounsellingMessage], Int32)' method, and this method cannot be translated into a store expression.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NotSupportedException: LINQ to Entities does not recognize the method 'MedicalApp.Domain.General.CounsellingMessage ElementAt[CounsellingMessage](System.Linq.IQueryable`1[MedicalApp.Domain.General.CounsellingMessage], Int32)' method, and this method cannot be translated into a store expression.
Source Error:
Line 43: for (int k = 0; k < PatientIDs.Length; k++) Line 44: { Line 45: PatientIDs[k] = messageObject.ElementAt(k).Chatname; Line 46: } Line 47:
嘗試更換此PatientIDs [K] = messageObject.ElementAt(k)的.Chatname;這個PatientIDs [k] = messageObject.ToList()[k] .Chatname; – jannagy02