實體這是模型我有我使用LINQ綁定泛型列表裏面enity
public class Physician
{
public Physician()
{
PhysicianAddress = new Address();
}
public int PhysicianId { get; set; }
public string NPI { get; set; }
public string PhysicianPrefixName { get; set; }
public string PhysicianFirstName { get; set; }
public string PhysicianMiddleName { get; set; }
public string PhysicianLastName { get; set; }
public string PhysicianPhoneExt { get; set; }
public string PhysicianPhoneNum { get; set; }
public string PhysicianFaxNum { get; set; }
public string PhysicianEmailAddr { get; set; }
public string PhysicianComment { get; set; }
public List<Site> PracticeLocationsList { get; set; }
public Address PhysicianAddress { get; set; }
public int? MergedIntoPhysicianId { get; set; }
}
我從StoredProcedure的獲取數據,然後我綁定的返回結果模型
數據綁定到它var physicians = (from sp in e.GetSitePhysicians((int)request.SiteId)
select new Physician()
{
PhysicianId = sp.PhysicianId,
PhysicianFirstName = sp.PhysicianFirstName,
PhysicianMiddleName = sp.PhysicianMiddleName,
PhysicianLastName = sp.PhysicianLastName,
NPI = sp.NPI,
PhysicianPhoneNum = sp.PhysicianPhoneNum,
PhysicianFaxNum = sp.PhysicianFaxNum,
PhysicianEndDate = sp.PhysicianEndDate,
PhysicianEffectiveDate = sp.PhysicianEffectiveDate,
PhysicianComment = sp.PhysicianComment,
AddressId = sp.AddressId,
PhysicianEmailAddr = sp.PhysicianEmailAddr,
PhysicianPhoneExt = sp.PhysicianPhoneExt,
PhysicianAddress = new Address()
{
SiteAddressId = sp.SiteAddressId ?? 0,
Street1 = sp.SiteAddressStreet1 ?? string.Empty,
Street2 = sp.SiteAddressStreet2 ?? string.Empty,
City = sp.SiteAddressCityName ?? string.Empty,
PostalCode = sp.SiteAddressPostalCode ?? string.Empty,
State = sp.GeographicalStateProvinceCode ?? string.Empty,
ParkingInstructions = sp.SiteAddressParkingInstructions ?? string.Empty,
},
PracticeLocationsList=new Site()
{
Id = sp.SiteId,
Name = sp.SiteName,
SiteMainPhoneNum = sp.SiteMainPhoneNum,
Address = new Address
{
SiteAddressId = sp.SiteAddressId??0,
Street1 = sp.SiteAddressStreet1,
Street2 = sp.SiteAddressStreet2,
City = sp.SiteAddressCityName,
PostalCode = sp.SiteAddressPostalCode,
State = sp.GeographicalStateProvinceCode
},
Contacts = new List<SiteContact>() { new SiteContact() }
}
}).ToList();
當我嘗試綁定我的網站對象到PracticeLocationsList它會產生編譯時錯誤,「不能隱式轉換類型'網站'爲'System.Collections.Generic.List'」。
如何將我的網站對象轉換爲列表,然後綁定?
我標誌着這是因爲答案首先@Yahya了答案。 – praveen