列表(模型)工厂

时间:2012-10-18 22:00:15

标签: c# asp.net-mvc-3 nhibernate

我想在数据列表中创建数据列表。我相信这很难解释,但我会尽力解释我的问题。我创建了数据列表,但在此列表中,一些参数也是数据列表。我必须使用此代码编写,因为这是限制(我们的工厂)。如果我获取的数据不是数据列表,那么一切正常。哪里有问题?如果我在列表中写列表,我会收到错误。也许你可以看到我的错误。

程序是编译。

问题(我使用NHibernate中的映射从第三个表中获取数据):

DestynationName = (List<dictionaryNewInfoSupportList>x.DictImportantInformationSDestination.Select(n=> new DictionaryNewInfoSupportList { Id = n.Destination.Id, Name = n.Destination.Desciption}).ToList();

模型中的DestynationName

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();

1 个答案:

答案 0 :(得分:1)

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();