Hello everyone,
I building a MVC 4 project with Entity Framework 6. There is have business layer and data access layer also both are have its own model classes.
If I want to get list of table values from sql table -> DAL -> BAL -> Controller, which is the fastest and best way retrieve list from each other without using foreach and automapper.dll ?
Eg:
DAL-->
- public class ProductsDAL{
- public List
GetProductCategoryTree() - {
- using (var context = new ReboxEntities())
- {
- return context.ProductCategories.ToList();
- }
- }
- }
BAL-->
- public class ProductCategoryBL
- {
- public List
GetProductCategories() - {
- ProductsDAL objProduct = new ProductsDAL();
- IList
lsRes = new List (); - lsRes = objProduct.GetProductCategoryTree();
- List
categories = new List (); - foreach (var item in lsRes)
- {
- categories.Add(new ProductCategoryDM{
- idProductCategory = item.idProductCategory,
- ProductCategoryName = item.ProductCategoryName,
- ProductCategoryDescription = item.ProductCategoryDescription,
- idParentCategoryProduct = item.idParentCategoryProduct,
- AlternateNamesToSearch = item.AlternateNamesToSearch,
- LevelID = item.LevelID,
- CompletePathName = item.CompletePathName,
- PCImage = item.PCImage
- });
- }
- return categories;
- }
then Controller,
- /*Inside Viewmodel folder*/
- public class SearchVM
- {
- public List
Res = new List(); - public SearchVM()
- {
- Res = new List
(); - }
- }
- /*End*/
- [HttpPost]
- public ActionResult Search()
- {
- ProductCategoryBL objProduct = new ProductCategoryBL();
- List
lsRes = new List (); - SearchVM vm = new SearchVM();
- lsRes = objProduct.GetProductCategories();
- vm.Res = lsRes;
- return PartialView("_searchresult", vm);
- }

Catcher WongPosted Jan 11, 2017, 3:26 AM
Abhilash J APosted Jan 11, 2017, 3:08 AM
Catcher WongPosted Jan 9, 2017, 1:08 AM