私は重複を避けるために、次のコードを使用しています:ラムダ式:IEnumerableではなくListにどのようにマップするのですか?
List<IncidentVM> incidents = db.Incident_Log.Select(mappingIncidentVM).ToList();
そして、それは私のViewModel IncidentVMにIncident_Logエンティティをマッピングします。その後、私は次の操作を行うことができます
private static Expression<Func<Incident_Log, IncidentVM>> mappingIncidentVM()
{
return x => new IncidentVM
{
incident_ID = x.incident_id,
incident_description = x.incident_description,
file_names = x.file_names,
location = x.location,
Actions =
x.Action_Log.Where(y => y.assigned_to == y.assigned_to).Select(z => new ActionVM
{
incident_ID = z.incident_id,
action_ID = z.action_id,
action_description = z.action_description
})
//actionList = new List<ActionVM>(d => mappingActionVM)
};
}
。 )
LINQ to Entities does not recognize the method System.Collections.Generic.List[ViewModel.ActionVM] ToList[ActionVM](System.Collections.Generic.IEnumerable([ViewModel.ActionVM]) method, and this method cannot be translated into a store expression.
ToListメソッド(:
private static Expression<Func<Incident_Log, IncidentVM>> mappingIncidentVM()
{
return x => new IncidentVM
{
incident_ID = x.incident_id,
incident_description = x.incident_description,
file_names = x.file_names,
location = x.location,
actionList =
x.Action_Log.Where(y => y.assigned_to == y.assigned_to).Select(z => new ActionVM
{
incident_ID = z.incident_id,
action_ID = z.action_id,
action_description = z.action_description
}).ToList()
};
}
しかし、それはエラーを投げている: 私の問題は、私は私はこのようなリストではなくIEnumerable.Somethingに直接マッピングことがしたいということです認識されません。ここで
は私のViewModelです:
public class IncidentVM
{
public int incident_ID { set; get; }
[Display(Name = "Description*")]
[Required]
public string incident_description { get; set; }
[Display(Name = "Specific Location*")]
[Required]
public string location { set; get; }
public string file_names { set; get; }
//Here is the problem, I 'd like to have only actionList
public IEnumerable<ActionVM> Actions { get; set; }
public List<ActionVM> actionList { get; set; }
そして、ここではAction_Logオブジェクトのためのモデルである:
public partial class Action_Log
{
public int action_id { get; set; }
public int incident_id { get; set; }
public string action_description { get; set; }
public virtual Incident_Log Incident_Log { get; set; }
}
が、この場合のリストに直接マップすることは可能ですか?
'y.assigned_to == y.assigned_to'? –
Action_Logは、部分クラスの他の部分でIQueryableを実装していますか?そうでなければ、どのようにクエリを実行していますか?部分クラスの他の部分を表示するようにOPを編集できますか? –
@GertArnoldコードから短くするためにいくつかのプロパティを削除しました... assigned_toはその1つ(文字列) – Sychal