2012-12-02 77 views
1

全部選擇我的這個選擇所有城市:與Lambda和EF

ExecuteStoreCommand<MCT_DBEntities>("select * from cities", ConnectionResolver.DB_Connection); 

現在我試圖將轉換爲LAMBDA,但我怎麼告訴它SELECT *

GetWithExpression<city, MCT_DBEntities>(u => u.SelectMany, ConnectionResolver.DB_Connection); 

編輯:

private static TValue RetryGetWithExpression<U,T, TValue>(Func<ObjectSet<T>, TValue> func, String connection, Int32 retryInfiniteLoopGuard = 0) 
     where T : class 
     where U : ObjectContext 
    { 
     Microsoft.Practices.TransientFaultHandling.RetryPolicy policy = RetryPolicyProvider.GetSqlAzureRetryPolicy(); 

     using (U entitiesContext = (U)Activator.CreateInstance(typeof(U), new[] { connection })) 
     {...} 

回答

1

如果你的第一個參數是Expression<Func<T, bool>>你可能想:

RetryGetWithExpression<city, MCT_DBEntities>(_ => true, ConnectionResolver.DB_Connection); 

編輯。 這應該工作:

RetryGetWithExpression<MCT_DBEntities, city, IQueryable<city>>(x => x.Select(y => y), 
             ConnectionResolver.DB_Connection); 
+0

這是我的函數功能:函數,T> FUNC – user1662812

+0

@ user1662812所以這是選擇?那麼'x => x'怎麼樣? – 2kay

+0

無法將lambda表達式轉換爲委託類型'System.Func ,DataAccessComponents.EntityDataModels.city>' – user1662812

0

你試過

GetWithExpression<city, MCT_DBEntities>(u => u.Select(), ConnectionResolver.DB_Connection); 
+0

無重載方法 '選擇' 取0參數 – user1662812