TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abhilash J A
533
2.4k
597.9k
C# - passing objects between business and data access layer
Jan 9 2017 12:31 AM
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<ProductCategory> GetProductCategoryTree()
{
using
(var context =
new
ReboxEntities())
{
return
context.ProductCategories.ToList();
}
}
}
BAL-->
public
class
ProductCategoryBL
{
public
List<ProductCategoryDM> GetProductCategories()
{
ProductsDAL objProduct =
new
ProductsDAL();
IList<ProductCategory> lsRes =
new
List<ProductCategory>();
lsRes = objProduct.GetProductCategoryTree();
List<ProductCategoryDM> categories =
new
List<ProductCategoryDM>();
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<ProductCategoryDM> Res =
new
List<ProductCategoryDM>();
public
SearchVM()
{
Res =
new
List<ProductCategoryDM>();
}
}
/*End*/
[HttpPost]
public
ActionResult Search()
{
ProductCategoryBL objProduct =
new
ProductCategoryBL();
List<ProductCategoryDM> lsRes =
new
List<ProductCategoryDM>();
SearchVM vm =
new
SearchVM();
lsRes = objProduct.GetProductCategories();
vm.Res = lsRes;
return
PartialView(
"_searchresult"
, vm);
}
Here is using too many foreach loop for mapping. How can I improve this? Please help me.
Reply
Answers (
3
)
how to integration of Aadhar in xamarin.android
How to implement Datalist inside Gridview in asp.net