如何更改分组列表< MyClass的>列出< MyAnotherClass>类型? [英] How can change grouped List<MyClass> to list<MyAnotherClass> type?

查看:146
本文介绍了如何更改分组列表< MyClass的>列出< MyAnotherClass>类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的代码;

 公开名单< SbtKlasorViewModel> GetFoldersWithIndexedDocuments()
{
// TODO - 我无法找到合适的查询。我们需要的文件,但只有文件夹使用哪个(ISession的会话= DatabaseProvider.SessionFactory.OpenSession())
{
名单,LT被索引
; DokumanlarModel> dokumanList = session.QueryOver< DokumanlarModel>()
。凡(X =>!x.IndexlenmeTarihi = NULL)
的.List()了ToList();

无功名单= dokumanList.GroupBy(X => x.Klasor.Aciklama);

名单,LT; SbtKlasorModel>文件夹=名单列表与LT; SbtKlasorModel取代;


////转化SbtKlasorModel到SbtKlasorViewModel为respose
名单,LT; SbtKlasorViewModel> transformedFolders =夹
。选择(X => ModelTransformer.TransformModel(X))。了ToList();


返回transformedFolders;
}


}



DokumanlarModel.cs

 公共类DokumanlarModel:SModuleClass 
{
公共虚拟INT DokumanId {搞定;组; }
公共虚拟字符串DokumanAdi {搞定;组; }
公共虚拟INT DosyaBoyutu {搞定;组; }
公共虚拟INT杜伦麦{搞定;组; }
公共虚拟字符串EskiPath {搞定;组; }
公共虚拟字符串IndexTahsisKullanici {搞定;组; }
公共虚拟的DateTime? IndexlenmeTarihi {搞定;组; }
公共虚拟字符串IndexleyenKullanici {搞定;组; }
公共虚拟字符串KaliteKontrolKullanici {搞定;组; }
公共虚拟的DateTime? KaliteKontrolTarihi {搞定;组; }
公共虚拟SbtKlasorModel Klasor {搞定;组; }
公共虚拟INT KlasordekiSira {搞定;组; }
公共虚拟DokNitelikTipModel NitelikTipId {搞定;组; }
公共虚拟INT OcrDurum {搞定;组; }
公共虚拟路径字符串{搞定;组; }
公共虚拟INT SayfaSayisi {搞定;组; }
公共虚拟的DateTime? TaranmaTarihi {搞定;组; }
公共虚拟字符串TarayanKullanici {搞定;组; }
公共虚拟INT Versiyon {搞定;组; }
公共虚拟字符串OrjinalPath {搞定;组; }
公共虚拟的IList< LogDokumanModel> LogDokumanList {搞定;组; }
公共虚拟的IList< DokumanlarOcrModel> DokumanlarOcrList {搞定;组; }
公共虚拟的IList< DokVersiyonModel> DokVersiyonList {搞定;组; }
公共虚拟的IList< DokMetaDataArsivModel> DokMetaDataArsivList {搞定;组; }

公共DokumanlarModel()
{
LogDokumanList =新的List< LogDokumanModel>();
DokumanlarOcrList =新的List< DokumanlarOcrModel>();
DokVersiyonList =新的List< DokVersiyonModel>();
DokMetaDataArsivList =新的List< DokMetaDataArsivModel>();
}
}



SbtKlasorModel.cs:

 公共类SbtKlasorModel:SModuleClass 
{
公共虚拟INT KlasorId {搞定;组; }
公共虚拟字符串Aciklama {搞定;组; }
公共虚拟字符串的Ada {搞定;组; }
公共虚拟字符串KisiAdSoyad {搞定;组; }
公共虚拟字符串Mahalle {搞定;组; }
公共虚拟字符串Parsel {搞定;组; }
公共虚拟字符串SerhAciklama {搞定;组; }
公共虚拟的DateTime SerhBaslangicTarihi {搞定;组; }
公共虚拟的DateTime SerhBitisTarihi {搞定;组; }
公共虚拟SbtKullaniciModel SerhKullanici {搞定;组; }
公共虚拟字符串Pafta {搞定;组; }
公共虚拟字符串KlasorNo {搞定;组; }
公共虚拟字符串SiraNo {搞定;组; }
公共虚拟字符串AciklamaYeni {搞定;组; }
公共虚拟的IList< IlskGrupKlasorModel> IlskGrupKlasorList {搞定;组; }
公共虚拟的IList< DokumanlarModel> DokumanlarList {搞定;组; }
公共虚拟的IList< DokTaleplerModel> DokTaleplerList {搞定;组; }

公共SbtKlasorModel()
{
IlskGrupKlasorList =新的List< IlskGrupKlasorModel>();
DokumanlarList =新的List< DokumanlarModel>();
DokTaleplerList =新的List< DokTaleplerModel>();
}
}



我喜欢从数据库列表数据。并以DokumanlarModel.Klasor.Aciklama分组。但我需要列出清单。我试着像上面。它返回null。我应该为这种变化做什么?


解决方案

 公开名单< SbtKlasorViewModel> GetFoldersWithIndexedDocuments()
{
使用(VAR会话= DatabaseProvider.SessionFactory.OpenSession())
{
VAR foldersContainingIndexedDocs = session.QueryOver< SbtKlasorModel>()
。 JoinQueryOver< DokumanlarModel>(X => x.DokumanlarList)
。凡(DOC =>!doc.IndexlenmeTarihi = NULL)
的.List();

//转化为SbtKlasorModel为SbtKlasorViewModel respose
返回folders.Select(ModelTransformer.TransformModel).ToList();
}
}


Here is my codes;

 public List<SbtKlasorViewModel> GetFoldersWithIndexedDocuments()
    {
        //TODO - I can't find right query. We need folders with documents but only documents which be Indexed
        using (ISession session = DatabaseProvider.SessionFactory.OpenSession())
        {
            List<DokumanlarModel> dokumanList = session.QueryOver<DokumanlarModel>()
                .Where(x => x.IndexlenmeTarihi != null)
                .List().ToList();

            var list = dokumanList.GroupBy(x => x.Klasor.Aciklama);

            List<SbtKlasorModel> folders = list as List<SbtKlasorModel>;


            ////Transforming SbtKlasorModel to SbtKlasorViewModel for respose 
            List<SbtKlasorViewModel> transformedFolders = folders
                .Select(x => ModelTransformer.TransformModel(x)).ToList();


            return transformedFolders;
        }


    }

DokumanlarModel.cs:

public class DokumanlarModel : SModuleClass
{
    public virtual int DokumanId { get; set; }
    public virtual string DokumanAdi { get; set; }
    public virtual int DosyaBoyutu { get; set; }
    public virtual int Durum { get; set; }
    public virtual string EskiPath { get; set; }
    public virtual string IndexTahsisKullanici { get; set; }
    public virtual DateTime? IndexlenmeTarihi { get; set; }
    public virtual string IndexleyenKullanici { get; set; }
    public virtual string KaliteKontrolKullanici { get; set; }
    public virtual DateTime? KaliteKontrolTarihi { get; set; }
    public virtual SbtKlasorModel Klasor { get; set; }
    public virtual int KlasordekiSira { get; set; }
    public virtual DokNitelikTipModel NitelikTipId { get; set; }
    public virtual int OcrDurum { get; set; }
    public virtual string Path { get; set; }
    public virtual int SayfaSayisi { get; set; }
    public virtual DateTime? TaranmaTarihi { get; set; }
    public virtual string TarayanKullanici { get; set; }
    public virtual int Versiyon { get; set; }
    public virtual string OrjinalPath { get; set; }
    public virtual IList<LogDokumanModel> LogDokumanList { get; set; }
    public virtual IList<DokumanlarOcrModel> DokumanlarOcrList { get; set; }
    public virtual IList<DokVersiyonModel> DokVersiyonList { get; set; }
    public virtual IList<DokMetaDataArsivModel> DokMetaDataArsivList { get; set; }

    public DokumanlarModel()
    {
        LogDokumanList = new List<LogDokumanModel>();
        DokumanlarOcrList = new List<DokumanlarOcrModel>();
        DokVersiyonList = new List<DokVersiyonModel>();
        DokMetaDataArsivList = new List<DokMetaDataArsivModel>();
    }
}

SbtKlasorModel.cs:

public class SbtKlasorModel : SModuleClass
{
    public virtual int KlasorId { get; set; }
    public virtual string Aciklama { get; set; }
    public virtual string Ada { get; set; }
    public virtual string KisiAdSoyad { get; set; }
    public virtual string Mahalle { get; set; }
    public virtual string Parsel { get; set; }
    public virtual string SerhAciklama { get; set; }
    public virtual DateTime SerhBaslangicTarihi { get; set; }
    public virtual DateTime SerhBitisTarihi { get; set; }
    public virtual SbtKullaniciModel SerhKullanici { get; set; }
    public virtual string Pafta { get; set; }
    public virtual string KlasorNo { get; set; }
    public virtual string SiraNo { get; set; }
    public virtual string AciklamaYeni { get; set; }
    public virtual IList<IlskGrupKlasorModel> IlskGrupKlasorList { get; set; }
    public virtual IList<DokumanlarModel> DokumanlarList { get; set; }
    public virtual IList<DokTaleplerModel> DokTaleplerList { get; set; }

    public SbtKlasorModel()
    {
        IlskGrupKlasorList = new List<IlskGrupKlasorModel>();
        DokumanlarList = new List<DokumanlarModel>();
        DokTaleplerList = new List<DokTaleplerModel>();
    }
}

I got data like List from database. And grouped by "DokumanlarModel.Klasor.Aciklama". But I need List list. I tried like above. It returns null. What should i do for this type change?

解决方案

public List<SbtKlasorViewModel> GetFoldersWithIndexedDocuments()
{
    using (var session = DatabaseProvider.SessionFactory.OpenSession())
    {
        var foldersContainingIndexedDocs = session.QueryOver<SbtKlasorModel>()
            .JoinQueryOver<DokumanlarModel>(x => x.DokumanlarList)
                .Where(doc => doc.IndexlenmeTarihi != null)
            .List();

        //Transforming SbtKlasorModel to SbtKlasorViewModel for respose
        return folders.Select(ModelTransformer.TransformModel).ToList();
    }
}

这篇关于如何更改分组列表&LT; MyClass的&GT;列出&LT; MyAnotherClass&GT;类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆