[英]Can anyone explain this “repository - entity”?
我在讀這篇文章:
http://ludwigstuyck.wordpress.com/2013/03/05/a-reference-architecture-part-3-2/
我看到了這段代碼:
public interface IRepository<T> where T : class
{
void Add(T entity);
void Update(T entity);
void Delete(T entity);
void Delete(Expression<Func<T, bool>> where);
IEnumerable<T> Query(Expression<Func<T, bool>> filter);
IEnumerable<T> QueryObjectGraph(Expression<Func<T, bool>> filter, string children);
}
我不是c#程序員,(我是python程序員)誰能解釋這個界面?
此存儲庫應向存儲庫添加一個實體,或更新現有實體,或刪除現有實體,但我無法理解此定義:
void Delete(Expression<Func<T, bool>> where);
和其他:
IEnumerable<T> Query(Expression<Func<T, bool>> filter);
這是為了檢索一些所需的實體? (如何通過過濾器?如地圖
{"id": ">5", "color": ["red", "blue"]},
還是簡單的DQL查詢STRING?
IEnumerable<T> QueryObjectGraph(Expression<Func<T, bool>> filter, string children);
我不了解這另一個功能,孩子的參數是什么? :/
Expression<Func<T, bool >>
通常對謂詞感到滿意,通常表示為lambda表達式
x => x.Property > 5 && x.OtherProperty.Contains( "foo" )
編譯器使用lambda創建表達式。
您要提出的問題可以概括為linq 。 一旦掌握了該主題,就應該開始理解所顯示的代碼。
Func<>
( 在這里 )是.NET的一個非常酷的部分。 它使我們能夠編寫更酷的lambda ! ( php也有lambda的 )
和
Expression<>
( 此處 )是定義以上所有內容的一種方法,以便可以“稍后解釋”。 最明顯的例子是實體框架,它將在需要時將lambda表達式轉換為SQL。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.