我希望使用 LINQ to SQL 和 C# 将连接表和项目的内容连接到视图模型中。
我的伪代码如下:
return (from t1 in db.Opportunities
from t2 in db.Leads.Where(x => x.Lead_ID == t1.Lead_ID)
from t3 in db.LeadAddresses.Where(x => x.Lead_ID == t2.Lead_ID).DefaultIfEmpty()
from t4 in db.Addresses.Where(x => x.Address_ID == t3.Address_ID).DefaultIfEmpty()
orderby (t1.Created) descending
select new FieldSalesPipelineViewModel
{
Id = t1.Opportunity_ID,
CompanyName = t2.Company_Name,
OpportunityTitle = t1.Opportunity_Title,
CompanyCity = ??????????
}).Take(howMany);
一个潜在客户可能有多个地址,但我只想在输出中返回一个城市结果,即来自 Addresses (t4.City)的唯一城市的逗号分隔列表
任何有关如何解决此问题的提示将不胜感激。