संभव डुप्लिकेट SQL का उपयोग करना चाहिए:
To return IQueryable<T> or not return IQueryable<T>मैं क्यों IQueryable <T> सूची <T> से अधिक LINQ में
मैं इस प्रकार के रूप में लागू एसक्यूएल भंडार करने के लिए LINQ की है। GetAll विधि IQueryable की बजाय एक सामान्य सूची को पुनर्प्राप्त कर रहा है। हालांकि अधिकांश उदाहरणों और ट्यूटोरियल पिट में IQueryable लौटने के लिए दिखाया गया है। IQueryable को पुनर्प्राप्त करने का क्या फायदा है?
using System.Linq;
namespace RepositoryLayer
{
public interface IRepository<T> where T : class
{
//System.Linq.IQueryable<T> GetAll();
System.Collections.Generic.List<T> GetAll();
}
public class Repository<T> : IRepository<T> where T : class
{
public System.Data.Linq.DataContext Context
{
get;
set;
}
//public virtual System.Linq.IQueryable<T> GetAll()
//{
// //GetAll is returning generic Queryable<T>.
// System.Linq.IQueryable<T> allItems = Context.GetTable<T>();
// return allItems;
//}
public virtual System.Collections.Generic.List<T> GetAll()
{
System.Linq.IQueryable<T> allItems = Context.GetTable<T>();
return allItems.ToList();
}
}
}
व्यापार लेयर
namespace BusinessLayerProject
{
public class AccountBusiness
{
//IRepository<T>
RepositoryLayer.IRepository<RepositoryLayer.Account> accountRepository;
public AccountBusiness(RepositoryLayer.IRepository<RepositoryLayer.Account> repo)
{
accountRepository = repo;
}
//public List<RepositoryLayer.Account> GetAllAccounts()
//{
// //LibraryManagementClassesDataContext context = new LibraryManagementClassesDataContext();
// //List<RepositoryLayer.Account> accontList = context.Accounts.ToList();
// System.Linq.IQueryable<RepositoryLayer.Account> acc = accountRepository.GetAll();
// return acc.ToList();
//}
public List<RepositoryLayer.Account> GetAllAccounts()
{
List<RepositoryLayer.Account> acc = accountRepository.GetAll();
return acc;
}
}
}
आपको यह धागा देखना चाहिए और मार्क ग्रेवल द्वारा जवाब देना चाहिए http://stackoverflow.com/questions/718624/to-return-iqueryablet-or-not-return-iqueryablet – Habib
सही, बंद करने के लिए बोतलें - 100% डुप्लिकेट। – TomTom