Using linq correctly in ASP.NET (Business Layer?)
这篇帖子的一个回复中列举了许多关于LINQ使用中层次划分的链接,很不错。
Using linq correctly in ASP.NET (Business Layer?)
Thursday, August 23, 2007 11:39 PMCederstrom
Hey,
I want to make sure im using linq the right way in my project, I hope someone will take a few minutes to help me in the right direction here
I have created a "LINQ to SQL Classes" to my project, which includes for example "Files". I have then created a new partial class called Files, where I define some of my own methods for Files. So when I want to make a list of files I can easilly make the following linq:
var Files = from f in db.Files
select f;
which returns a list of File objects with my own functions added on.
What I am a bit confused about is how to make my business Layer correctly? Since I already can add business code in the partial class, do I skip everything else? Or do I make sure all my linq is put into some business class? ...
I hope someone will spend a few minutes, or someone have a link to a good article about the subject.
Thanks
All Replies
Friday, August 24, 2007 11:09 AMBen Hall _UK_MVP
Hi,
There are a number of approaches you could take. You could have your DA query and return a List<> of items to the BU where the BU then does processing etc and returns it to your presentation layer for binding. Or you could have your DABU return directly to the UI.
One approach:
DA - Your datacontext.
BU - Gets data from your datacontext, does any processing etc.
UI - Binds data received from BU.
Scott Guthrie mentioned in his blog that he sees people merging there BU and DAL when using Linq, which I can see the benefits too and what sounds like you are doing. (http://weblogs.asp.net/scottgu/archive/2007/06/29/linq-to-sql-part-3-querying-our-database.aspx#2977727)
Adding business logic/validation is discussed here
http://weblogs.asp.net/scottgu/archive/2007/07/11/linq-to-sql-part-4-updating-our-database.aspx
Granville has done a good article on this and you might want to follow his approach and the way he has split the layers.
http://dotnetslackers.com/articles/csharp/IntroducingLINQ4.aspx
Ian Cooper's article might also provide you with some information
http://iancooper.spaces.live.com/Blog/cns!844BD2811F9ABE9C!397.entry
Hope this helps, gives you a bit of reading anyway. Any more questions then please ask.
Ben
Friday, August 24, 2007 1:25 PMBen Hayat
Sir Ben;
Thank you for great links; Where do you find all these great links. I knew about Scott's (since I'm glued to that blog), but the rest are very good as well. Go more to read.
Thanks again!
Check out this link too
http://blogs.microsoft.co.il/blogs/aviwortzel/archive/2007/08/17/DLINQ-_1320_-Advanced-topics-_1320_-how-it-works-in-ASP.NET-application-_1320_-part-5.aspx
He also brings up a good point about why the code generator tools, do not set the "UpdateCheck" property! Something for discussion!