开发者

How to fill business object from dal

I'm returning DataTable in DAL. And I have a businessObject called Customer. Where should开发者_JAVA技巧 I fill this object? Should it be done in DAL? Or in my front-end app? or where? A little cofused.


If at all possible, you want to avoid returning DataTable in your DAL and instead return the properly filled business object. There are several tools that will help you with this, for example LINQ to SQL, Entity Framework, or (my current favorite) Dapper.NET (used by this very site). I like Dapper best because it's lightweight and works well with a Data Repository pattern, which I frequently use.


You could have a Base DAL, which returns DataTables. Then have an Upper DAL, which does the converting to and from entities, (this is what I tend to use)

You really shouldn't be referring to DataTables in your UI layer.

A half-way house that I have seen before is doing the 'object filling' within a method in the actual business object itself, but that doesn't allow you to switch out your DAL so easily.


When crossing domains like this, where the representation of the data is different in each, you need an integration layer that will take care of the mapping between both representations. Most ORM tools do that mapping for you automatically, though.

But to stick with your example, you could have a layer of mappers to do that. CustomerMapper would then map from the DataTable to the Customer, effectively bridging the two domain representations.


It should be done in BL or Business Logic layer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜