簡體   English   中英

如何使用params關鍵字讀取參數並實現函數

[英]how to read the parameter with params keyword and implementing a function

嗨,我這里有一個代碼片段。 這不是我的,在學習如何處理Entity Framework我在互聯網上看到了這個,我知道它只包含(急於加載)導航屬性,然后將其返回為IQueryable

我想知道的是:

  1. 您如何閱讀此參數params System.Linq.Expressions.Expression<Func<T, object>>[] includeProperties

  2. 您如何調用或使用此功能? (應該通過收集,對嗎?舉個小例子會很有幫助,因為我在看一些演示時會以某種方式學習)

     public IQueryable<Customer> AllIncluding(params System.Linq.Expressions.Expression<Func<T, object>>[] includeProperties) { var query = context.Customers; foreach (var includeProperty in includeProperties) { query = query.Include(includeProperty); } return query; } 

任何幫助將非常感激。 謝謝!

params使您可以將數組參數作為實際數組或值的開放式列表傳遞:

var includes = new Expression<Func<Customer, object>>[] 
    { 
        i => i.SubProperty1, 
        i => i.SubProperty2
    };
var query = db.Entities.AllIncluding(includes);

要不就

var query = db.Entities.AllIncluding(i => i.SubProperty1, i => i.SubProperty2);

我正在猜測具體的類型和屬性,但希望您能理解。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM