linq を使用して、別のオブジェクト リストをデータメンバーとして含むオブジェクトのリストを返そうとしています。示されている例を試しましたが、試行ごとに異なるエラーが発生し続けます。その 1 つは次のとおりです。LINQ to Entities はメソッド 'System.Collections.Generic.List 1[SunGard.Tools.Notifications.LinkVariable] ToList[LinkVariable](System.Collections.Generic.IEnumerable
1[SunGard.Tools.Notifications.LinkVariable])' メソッドを認識せず、このメソッドはストア式に変換できません。
いくつかの文字列データメンバーと別のオブジェクトのリスト (List) を含むオブジェクト (AlertMessageReturn) があります。LinkVarible を定義するクラスと、値を含むテーブルがあります。私のクエリは次のようになります。
AlertMessagesQuery = from alertMessage in this.context.AlertMessages
where alertMessage.UserId=UserId
select new AlertMessageReturn()
{ PAM_ShortMessage = alertMessage.PAM_ShortMessage,
PAM_LongMessage = alertMessage.PAM_LongMessage,
PAM_LongMessageRemote = alertMessage.PAM_LongMessageRemote,
LinkVariables = (from linkVariable in this.context.AlertMessageLinks
from user in this.context.AlertMessageUsers
where user.PAMU_PAM_ID == linkVariable.PAML_PAM_ID && user.PAMU_UserId == UserId
select new LinkVariable()
{
Name = linkVariable.PAML_SessionVariableName,
Value = linkVariable.PAML_SessionVariableValue
})
};
このエラーは、リンク変数に対して返される型に関連しています。助けてください。
次のようにコードを変更しました。
LinkDataQuery = from linkData in this.context.AlertMessageLinks
from user1 in this.context.AlertMessageUsers
where user1.PAMU_PAM_ID == linkData.PAML_PAM_ID && user1.PAMU_UserId == UserId
select new LinkData
{
Name = linkData.PAML_SessionVariableName,
Value = linkData.PAML_SessionVariableValue
};
var links = LinkDataQuery.ToList();
AlertMessagesQuery = from alertMessage in this.context.AlertMessages
where alertMessage.UserId=UserId
select new AlertMessageReturn()
{ PAM_ShortMessage = alertMessage.PAM_ShortMessage,
PAM_LongMessage = alertMessage.PAM_LongMessage,
PAM_LongMessageRemote = alertMessage.PAM_LongMessageRemote,
LinkVariables = links
};
var AlertMessages = AlertMessagesQuery.ToList(); // this is where the error point to
if (AlertMessages.Any())
{
return AlertMessages;
}
System.NotSupportedException: Unable to create a constant value of type 'SunGard.Tools.Notifications.LinkData' というエラーが表示されます。このコンテキストでは、プリミティブ型 (Int32、String、および Guid など) のみがサポートされます。