我想从PriceAssocationLookup和PriceAssociation表中获取结果集。如何执行此操作而不会因匿名类型而出错? 这是我的代码:
IEnumerable<IPriceAssociationLookupRepository> IPriceAssociationLookupRepository.GetPacs(string upc)
{
using (PortalDataEntities entities = new PortalDataEntities())
{
var priceAssociationLookups = (from priceassociationlookup in entities.PriceAssociationLookups
join priceassociation in entities.PriceAssociations on priceassociationlookup.PriceAssociationCode equals priceassociation.PriceAssociationCode
where priceassociationlookup.Upc == upc
select priceassociationlookup ).ToList();
return priceAssociationLookups;
}
}
答案 0 :(得分:1)
为要返回的列创建 ViewModel 并添加属性,并返回视图模型类型的列表,这是我的代码,我以前的方式:
List<PreviousTest> Result = (from d in db.dc_tpatient_bookingd
join og in db.dc_tp_organization
on d.clientid equals og.OrgId into a
from og in a.DefaultIfEmpty()
from t in db.dc_tp_test
from p in db.dc_tp_tprocess
where d.bookingid == BookingID
&& t.TestId == d.testid
&& d.ProcessID == p.processid
&& d.bookingdid != BookingDID
select new PreviousTest
{
BookingID = d.bookingid,
BookingDId = d.bookingdid,
TestID = t.TestId,
TestName = t.Test_Name,
ProcessName = p.name,
ProcessID = p.processid,
ClientID = d.clientid
}).ToList();
这是我的viewmodel:
public class PreviousTest
{
public long BookingID { get; set; }
public long BookingDId { get; set; }
public long TestID { get; set; }
public string TestName { get; set; }
public long ProcessID { get; set; }
public string ProcessName { get; set; }
public string ClientID { get; set; }
}