比方說,我有一個名爲Client
的實體和分表。 Client
有一個外鍵 - CountryId
連接到Countries
表。具有鑑別器的項目列表
ClientA
,ClientB
和ClientC
繼承自Client
。
我想列出我的系統中的所有客戶端(包括那些帶有空countryId的客戶端)以及他們的具體類型(鑑別器值)和國家名稱。
我的查詢看起來是這樣的:
from client in DbContext.Set<Client>()
from country in DbContext.Set<Country>().Where(x => x.Id == client.CountryId).DefaultIfEmpty()
where !(client is Salon)
select new
{
Id = client.Id,
Name = client.ClientName,
ClientClass = "TODO",
CountryName = country.CountryName
};
我的問題:我怎樣才能選擇鑑別價值?請注意代碼中的「TODO」,此處我卡住了。
謝謝!
如果你只是想要的類型名稱將'client.GetType()。toString()方法'無法勝任的字符串? – Brandon 2014-09-04 15:46:21
我的不好,錯過了「具體類型」的要求......在這種情況下'client.GetType()'? – Brandon 2014-09-04 15:47:07
我已經嘗試過沒有成功。我得到:'System.NotSupportedException:LINQ to Entities不能識別方法'System.Type GetType()'方法,並且這個方法不能被轉換成存儲表達式' – ofirbt 2014-09-04 15:54:24