我想在数据列表中创建数据列表。我相信这可能很难解释,但我会尝试非常清楚地解释我的问题。我创建了数据列表,但在此列表中,一些参数也是数据列表。我必须使用此代码编写,因为这是限制(我们的工厂)。如果我获取不是数据列表的数据,则一切正常。问题在哪里?如果我在列表中写列表,我会出错。或许你可以看出我的错误。
程序正在编译。
问题(我在 NHibernate 中使用映射从第三个表中获取数据):
DestynationName = (List<dictionaryNewInfoSupportList>x.DictImportantInformationSDestination.Select(n=> new DictionaryNewInfoSupportList { Id = n.Destination.Id, Name = n.Destination.Desciption}).ToList();
模型中的目标名称
public Ilist<dictionaryNewInfoSupportList> DestynationName;
类:
class dictionaryNewInfoSupportList
{
public string Name {get; set;}
public int Id {get; set;}
}
重要:
public IEnumerable<DictionaryListModel> OnList(DictionayDisplayModel dictionary DisplayModel, int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
{
var displayModel = (DictionaryNewInfoDisplayModel)dictionaryDisplayModel;
if (displayModel == null)
var list = _dictImportantInformation.GetList().Select(
x=> new DictionaryNewInfoListModel
{
Id = x.Id
Description = x.Description,
IsActiveYN = x.IsActive,
DestynationName = (List<DictionaryNewInfoSupportList>) x.DictImportantInformationXDestination.Select(n => new DictionaryNewInfoSupportList
{ Id = n.Destination.Id, Name = Destination.Description}).To.List()
}
).ToList();
return list;
}
我已经得到答案(主题已关闭)
var list = _dictImportantInformation.GetList().ToList().Select(
x => new DictionaryNewInfoListModel
{
Id = x.Id,
Description = x.Description,
IsActiveYN = x.IsActive,
DeestynationName = x.DictImportantInformationXDestination.Select(n => new DictionaryNewInfoSupportList
{ Id = n.Destination.Id, Name = n.Destination.Description }).ToList()
}
).ToList();
最佳答案
var list = _dictImportantInformation.GetList().ToList().Select(
x => new DictionaryNewInfoListModel
{
Id = x.Id,
Description = x.Description,
IsActiveYN = x.IsActive,
DeestynationName = x.DictImportantInformationXDestination.Select(n => new DictionaryNewInfoSupportList
{ Id = n.Destination.Id, Name = n.Destination.Description }).ToList()
}
).ToList();
关于c# - 列表中的列表(模型)工厂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12964437/