J
Justin Dutoit
Hey. I've been doing some reading and my first conclusion is that it seems
to me that LINQ to entities will be around for awhile.
Regarding performance though, before LINQ we all used stored procedures
because they are compiled and the fastest way to get data. I'd appreciate
some opinions on what the equivalent is now, i.e. best practice data layer
code using LINQ.
We also used to have wrappers for stored procs in the data layer (now LINQ
queries), and we unpacked the results into List<MyObject> in the business
layer. Opinions on the little business layer and data layer methods below
pls? Thanks for your time.
// In business layer file
public List<Product> GetSecondaryProducts(string categorySecondary)
{
List<Product> productList = new List<Product>();
Product thisProduct;
foreach (Products theProduct in
DefineSecondaryProducts(categorySecondary))
{
thisProduct = new Product();
thisProduct.Brand = theProduct.Brand;
thisProduct.ProductName = theProduct.Productname;
thisProduct.Price = theProduct.Price;
productList.Add(thisProduct);
}
return productList;
}
// In 'data' layer file
public IQueryable<Products> DefineSecondaryProducts(string
categorySecondary)
{
Quickshop35sp1 QS35sp1Entities = new Quickshop35sp1();
ObjectQuery<Products> products = QS35sp1Entities.ProductsSet;
IQueryable<Products> productsQuery =
from p in products
where p.CategorySecondary ==
categorySecondary
select p;
return productsQuery;
}
to me that LINQ to entities will be around for awhile.
Regarding performance though, before LINQ we all used stored procedures
because they are compiled and the fastest way to get data. I'd appreciate
some opinions on what the equivalent is now, i.e. best practice data layer
code using LINQ.
We also used to have wrappers for stored procs in the data layer (now LINQ
queries), and we unpacked the results into List<MyObject> in the business
layer. Opinions on the little business layer and data layer methods below
pls? Thanks for your time.
// In business layer file
public List<Product> GetSecondaryProducts(string categorySecondary)
{
List<Product> productList = new List<Product>();
Product thisProduct;
foreach (Products theProduct in
DefineSecondaryProducts(categorySecondary))
{
thisProduct = new Product();
thisProduct.Brand = theProduct.Brand;
thisProduct.ProductName = theProduct.Productname;
thisProduct.Price = theProduct.Price;
productList.Add(thisProduct);
}
return productList;
}
// In 'data' layer file
public IQueryable<Products> DefineSecondaryProducts(string
categorySecondary)
{
Quickshop35sp1 QS35sp1Entities = new Quickshop35sp1();
ObjectQuery<Products> products = QS35sp1Entities.ProductsSet;
IQueryable<Products> productsQuery =
from p in products
where p.CategorySecondary ==
categorySecondary
select p;
return productsQuery;
}