使用我們以前的ORM,OpenAccess
,我們能夠在查詢的select語句中包含幫助器方法。例如,將SQL數據與高速緩存的應用程序數據組合在一起。在實體框架查詢中使用幫助器方法
切換到實體框架6.x中後我們得到象這樣的錯誤:
LINQ到實體無法識別方法「System.String GetProductTranslation」
的靈查詢看起來是這樣的:
var products = (from p in db.Products
join cp in db.CustomerPrices on p.ProductId equals cp.ProductId
where p.LockedSince.Equals(null)
&& ... etc etc etc
select new
{
ProductId = p.ProductId,
Name = TranslationHelper.GetProductTranslation(p.ProductId, ProductTranslationField.Name, p.Name),
Description2 = TranslationHelper.GetProductTranslation(p.ProductId, ProductTranslationField.Description2, p.Description2),
Description3 = TranslationHelper.GetProductTranslation(p.ProductId, ProductTranslationField.Description3, p.Description3),
Description4 = TranslationHelper.GetProductTranslation(p.ProductId, ProductTranslationField.Description4, p.Description4),
... etc etc etc
});
在這種情況下,GetProductTranslation
方法從應用程序緩存抓住轉換數據防止在數據庫中使用無限量的連接和壓力。
使用Entity Framework 6.x複製這個最好的方法是什麼?
爲什麼只是沒有通過sql查詢拆分出來那會返回產品的神經數據和另一種方法來檢索你從緩存中獲取的內容? –