我想用linq獲取數據列表,但我得到這個錯誤。無法創建類型爲「Domain.DataModel.Hospital」的常量值。在這種情況下只支持基本類型或枚舉類型
不久,我的問題是:
我有一個Hospital
模型。該模型由城市code.All城市代碼爲十進制類型。(1,2,3,4,...等)
另外我有一個Person
和PersonStatu
models.Person和PersonStatu與TcKimlik
物業相關。和Hospital
模型PersonStatu
的HospitalCode
財產。
所以,當我試圖去通過城市代碼的醫院,如果城市代碼大於10時,小於10就不可能返回任何data.And它出現此錯誤是works.But:
Unable to create a constant value of type 'Domain.DataModel.Hospital'. Only primitive types or enumeration types are supported in this context.
這裏是我的Hospital
型號:
[Table("SPTS.HOSPITALS")]
public partial class Hospital
{
....
public decimal? IL_KODU { get; set; }
....
}
這裏是我的Querable LINQ查詢:
var hospitals = context.Hospitals.Where(p=>p.IL_KODU==1);
var persons = (from c in context.Persons
join x in context.PersonStatus on c.TcKimlik equals x.Tckn
join h in hospitals on x.HospitalCode equals h.KURUM_KODU
where x.Statu == true
select new DataViewModel
{
Id = c.Id,
TcKimlik = c.TcKimlik,
Uyruk = c.Uyruk,
Ad = c.Ad,
Soyad = c.Soyad,
Cinsiyet = c.Cinsiyet,
DogumTarihi = c.DogumTarihi,
KurumStatu = h.PAYDAS,
KurumKodu = h.KURUM_KODU,
KurumAdi = h.KURUM_ADI,
BranchName = c.Brans.BranchName,
AcademicTitleName = c.AkademikUnvan.Title,
ManagerialTitleName = c.IdariUnvan.Title,
StaffStatuName = c.Durum.Statu,
BranchTypeName = c.Unvan.Type,
ServiceClassName = c.Unvan.ServiceClass.Name,
City = h.KURUM_ILI,
CityCode = h.IL_KODU,
CityTownName = h.KURUM_ILCESI
}).AsQueryable();
那麼我能做些什麼來解決這個問題?
任何幫助,將不勝感激。
感謝。