第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法將類型 IEnumerable 轉換為列表 C#

無法將類型 IEnumerable 轉換為列表 C#

C#
紅顏莎娜 2022-12-24 12:45:03
我正在嘗試將列表帶到frontEnd. 我正在使用 mongoDb。我mongodb有一個名為 的集合Employee。Employee具有以下屬性public class EmployeeViewModel{    [BsonId(IdGenerator = typeof(StringObjectIdGenerator))]    public string ownerId { get; set; }    public string atributeChange { get;  set; }    public PersonalDataViewModel personalData { get; set; }    public AddressViewModel address { get; set; }    public List<EmailsViewModel>  emails { get; set; }    public SyndicateViewModel syndicate { get; set; }    public List<DependentsViewModel> dependents { get; set; }    public List<PhoneViewModel> phone { get; set; }    public List<BankViewModel> bank { get; set; }    public AttributesViewModel attributes { get; set; }    public List<BenefitsViewModel> benefits { get; set; }    public TransportViewModel transport { get; set; }    public List<AttachmentsViewModel> attachments { get; set; }    public List<DocumentsViewModel> documents { get; set; }    public List<DocumentsImagesViewModel> DependentsDocuments { get; set; }    public List<AttachmentsViewModel> DependentsAttachments { get; set; }    public List<BenefitsViewModel> DependentsBenefits { get; set; }}在此Model,我有一個名為:的屬性public List <DocumentsImagesViewModel> DependentsDocuments {get; set; }:public class DocumentsViewModel{    [BsonId]    public string ownerId { get; set; }    public string id { get; set; }    public string dependentId { get; set; }    public string number { get; set; }    public DateTime expiration { get; set; }    public List<DocumentsImagesViewModel> images { get; set; }    public List<DocumentPropertiesViewModel> properties { get; set; }    public DocumentTypeViewModel type { get; set; }}我正在嘗試帶來包含 depedentID 參數(shù)相等的好處。當我使用這個方法時,它有一個無法轉換的錯誤。IEnumerable 列出 C#
查看完整描述

2 回答

?
jeck貓

TA貢獻1909條經(jīng)驗 獲得超7個贊

LINQ 的.Where回報IEnumerable<T>,你的模型需要一個List<T>,你可以改變你的模型,IEnumerable<T>或者你可以改變這行代碼:

DependentsDocuments = employee.DependentsDocuments
                              .Where(x => x.dependentId == dependentId)

對此:

DependentsDocuments = employee.DependentsDocuments
                              .Where(x => x.dependentId == dependentId)
                              .ToList()


查看完整回答
反對 回復 2022-12-24
?
幕布斯6054654

TA貢獻1876條經(jīng)驗 獲得超7個贊

將您的代碼更改為此代碼可能有效:


public async Task<List<Documents>> GetDocument(string ownerId, string dependentId)

        {

            var query = (from employee in _employee.AsQueryable()

                        where employee.ownerId == ownerId

                        select new Employee()

                        {

                           DependentsDocuments  = employee.DependentsDocuments.Where(x => x.dependentId == dependentId).ToList()                            

                        }).ToList();               

            return query.ToList();

        }


查看完整回答
反對 回復 2022-12-24
  • 2 回答
  • 0 關注
  • 87 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號