How can change grouped List<MyClass> to list<MyAnotherClass> type?

放肆的年华 提交于 2019-12-23 03:26:12

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/32839483/how-can-change-grouped-listmyclass-to-listmyanotherclass-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!