Normally LINQ to SQL seems to be designed for 2 -tier program, especially when we use Visual Studio to visually create entities and DataContexts. No doubt, this is a very rapid way of developing a data access layer and using its classes for data operations. But when developing an enterprise application which is divided into multiple layers i.e. Data Access Layer, Business Layer, Service Layer and Presentation layer, etc. then developer gets confused in separating the business objects with the data access layer and to make them loosely coupled.
However, in order to utilize the LINQ to SQL for enterprise architecture I did some R & D and came to know that there are some methods supported by LINQ to SQL which helps to design a data access layer that is independent with the business objects. This helps the developer to use the same business objects even they are data contracts (specifically when talking in terms of WCF framework) or any other common business types.
Below procedure shows the way you can utilize the LINQ to SQL in multi tier architecture.
1. Create a Data Types layer which contains all types of business objects.
2. Create an empty BaseEntity class by which all the business objects will be inherited from. You can also put common properties under BaseEntity class like CreatedOn, CreatedBy, UpdatedOn, UpdatedBy usually common in all business objects.
public class BaseEntity
{
}
3. Now create a business object in our example its “Condition” class. [Note the property name should be equal to the result set column names of the procedure being called].
public class Condition :BaseEntity
{
Int32 conditionId;
public Int32 ConditionId
{
get { return conditionId; }
set { conditionId = value; }
}
String conditionName;
public String ConditionName
{
get { return conditionName; }
set { conditionName = value; }
}
String conditionDescription;
public String ConditionDescription
{
get { return conditionDescription; }
set { conditionDescription = value; }
}
}
4. Now create a Data Access Layer. Create a class Library Project and add LinqToSql, you may notice that .dbml file will be added into the solution. This provides the datacontext classes available to perform data operations.
5. Next, create a PersistanceManager class and adds following method. Here I have developed a wrapper of LINQ to SQL ExecuteQuery which provides the automatic binding of the type T and returns the List of T.
public List ExecuteQuery(String queryName, params Object[] param) where T : DataTypes.BaseEntity
{
List lst = new List();
using (DDMSDataContext context = new DDMSDataContext())
{
var items = context.ExecuteQuery(typeof(T), queryName, param);
foreach (var item in items)
{
T t;
t = (T)item;
lst.Add(t);
}
}
return lst;
}
As shown above, this method executes the procedure with the parameters supplied and returns the business object List to user. Once this is done you can call this method from Business layer or any other layer as follows
public List GetAllMedicalConditionsByConditionType(Int32 TypeId)
{
List lstMedConditions = PersistanceManager.GetInstance().ExecuteQuery("Exec SelectAllActiveMedicalConditionsByConditionType {0}", TypeId);
return lstMedConditions;
}
I like this web site it’s a master piece! Glad I found this on google.
I have recently started a website, the info you offer on this site has helped me tremendously. Thank you for all of your time & work. “It is no use saying, ‘We are doing our best.’ You have got to succeed in doing what is necessary.” by Sir Winston Churchill.
What’s Happening i’m new to this, I stumbled upon this I’ve found It absolutely useful and it has aided me out loads. I hope to contribute & aid other users like its helped me. Great job.
I like what you guys are up also. Such smart work and reporting! Carry on the excellent works guys I have incorporated you guys to my blogroll. I think it will improve the value of my web site :). “As is a tale, so is life not how long it is, but how good it is, is what matters.” by Lucius Annaeus Seneca.
Keep up the wonderful piece of work, I read few blog posts on this site and I believe that your site is really interesting and has sets of good information.
Really nice design and style and great articles , practically nothing else we need : D.
Its such as you read my mind! You appear to understand a whole lot about this, like you wrote the e-book in it or something. I believe which you simply could do with several % to force the message residence a bit, however other than that, this really is amazing blog. A terrific read. I’ll definitely be back.
Enjoyed looking at this, very good stuff, thankyou .
I like this website its a master peace ! Glad I observed this on google. “Live…..Laugh…..GOLF” by Kathryn Schaefer Plaum.
Hello there! Do you use Twitter? I’d like to follow you if that would be okay. I’m undoubtedly enjoying your blog and look forward to new posts.
Real good information can be found on web site.
With thanks a ton to generally be our advisor about this area. Many of us appreciated your actual article completely and the majority of all enjoyed reading how you handled the areas I regarded as being controversial. You’re always really kind in direction of readers like me and help me in my everyday life. Thanks.
Some really good posts on this site, thanks for contribution.
Great write-up, I am normal visitor of one’s blog, maintain up the nice operate, and It is going to be a regular visitor for a lengthy time.
Thanks for sharing superb informations. Your web site is very cool. I’m impressed by the details that you’ve on this site. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for extra articles. You, my pal, ROCK! I found simply the information I already searched all over the place and just couldn’t come across. What an ideal web site.
I truly appreciate this post. I have been looking everywhere for this! Thank goodness I found it on Bing. You have made my day! Thanks again!
Very interesting details you have noted, regards for posting.
As soon as I discovered this web site I went on reddit to share some of the love with them.
Normally I don’t read article on blogs, however I wish to say that this write-up very pressured me to check out and do so! Your writing taste has been amazed me. Thank you, quite nice post.
I have been examinating out a few of your articles and i must say clever stuff. I will surely bookmark your blog.
What’s Taking place i am new to this, I stumbled upon this I have found It positively useful and it has helped me out loads. I’m hoping to give a contribution & aid different users like its helped me. Great job.
I consider something genuinely interesting about your weblog so I saved to favorites .
I am impressed with this internet site , really I am a big fan .
Rattling wonderful information can be found on site . “I know of no great men except those who have rendered great service to the human race.” by Francois Marie Arouet Voltaire.
You are my inspiration , I own few web logs and rarely run out from to brand.
Some genuinely select content on this internet site , saved to fav.
I was studying some of your articles on this internet site and I conceive this website is very instructive! Continue posting.
I dugg some of you post as I cerebrated they were very beneficial very beneficial
I truly appreciate this post. I have been looking everywhere for this! Thank goodness I found it on Bing. You’ve made my day! Thanks again!
I like this blog very much so much excellent info.
I would like to thank you for the efforts you have put in writing this blog. I am hoping the same high-grade site post from you in the upcoming as well. In fact your creative writing skills has inspired me to get my own website now. Actually the blogging is spreading its wings rapidly. Your write up is a great example of it.
Absolutely indited articles, Really enjoyed reading through.
Thanks , I have lately been searching for details about this subject for ages and yours may be the very best I’ve discovered till now. But, what about the conclusion? Are you positive about the source?
Simply wanna comment on few general things, The website design is perfect, the subject material is real fantastic : D.
Thank you for any other excellent post. Where else could anybody get that type of information in such an ideal approach of writing? I’ve a presentation next week, and I am at the look for such info.
Absolutely pent written content, Really enjoyed reading through.
Thank you for your original and also appealing information.
Very interesting information!Perfect just what I was looking for!
Fantastic site. Plenty of helpful information here. I am sending it to a few buddies ans also sharing in delicious. And obviously, thanks on your effort!
I believe this internet site has got very superb indited subject matter articles.
I truly appreciate this post. I have been looking all over for this! Thank goodness I found it on Bing. You have made my day! Thank you again!
I’ve just subscribed to your RSS feed. I love your content and information..
I think other site proprietors should take this web site as an model, very clean and fantastic user friendly style and design, let alone the content. You are an expert in this topic!
Its such as you read my mind! You appear to understand so much about this, like you wrote the book in it or something. I think that you can do with some p.c. to force the message house a bit, but instead of that, that is magnificent blog. A fantastic read. I will definitely be back.
hello!,I really like your writing so so much! share we keep up a correspondence more approximately your post on AOL? I require an expert on this area to solve my problem. May be that’s you! Taking a look forward to peer you.
I like this web blog very much, Its a very nice place to read and get information.
Thanks for the info, I must bookmark your website for my reference
That is really interesting, You’re an excessively skilled blogger. I have joined your rss feed and stay up for in quest of extra of your great post. Also, I have shared your website in my social networks!
This blog is incredible
I think this web site contains some real great info for everyone :D. “I like work it fascinates me. I can sit and look at it for hours.” by Jerome K. Jerome.
Wow that was unusual. I just wrote an incredibly long comment but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing all that over again. Anyways, just wanted to say fantastic blog!
Awesome looking website. I recently built mine and I was looking for some design ideas and you gave me a few. Can I ask you whether you developed the website by youself?
I consider something really special in this website.
Very interesting points you have noted, appreciate it for putting up.
I always was concerned in this topic and stock still am, thanks for posting .
What a information of un-ambiguity and preserveness of valuable know-how about unpredicted emotions.
You have observed very interesting points! ps decent site.
I’d like to find out more? I’d want to find out some additional information.
We wish to thank you again for the wonderful ideas you gave Janet when preparing her post-graduate research and also, most importantly, pertaining to providing all of the ideas in one blog post. If we had been aware of your web-site a year ago, i’d have been rescued from the useless measures we were implementing. Thanks to you.
Real excellent information can be found on blog .
It’s a pity you don’t have a donate button! I’d without a doubt donate to this brilliant blog! I suppose for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this site with my Facebook group. Chat soon!
Great post. I just stumbled upon your blog and wanted to say that I have really enjoyed browsing your blog posts. In any case I’ll be subscribing to your feed and I hope you write again soon!
Someone essentially assist to make severely articles I’d state. That is the first time I frequented your website page and up to now? I surprised with the research you made to create this particular post amazing. Excellent activity!
I enjoy what you guys are usually up too. This type of clever work and exposure! Keep up the terrific works guys I’ve added you guys to my personal blogroll.
Real nice pattern and wonderful subject material, nothing else we require :D.
I always was interested in this subject and stock still am, appreciate it for putting up.
You have observed very interesting points! ps nice website.
Appreciate it for all your efforts that you have put in this. Very interesting info. “I quote others only in order the better to express myself.” by Michel Eyquem de Montaigne.
I simply wanted to thank you yet again for this amazing web page you have developed here. It is full of useful tips for those who are seriously interested in this kind of subject, especially this very post. You really are all really sweet and also thoughtful of others and also reading the blog posts is an excellent delight with me. And thats a generous present! Tom and I are going to have enjoyment making use of your tips in what we need to do in a few weeks. Our list is a kilometer long and simply put tips will be put to good use.
I believe this internet site has some very good information for everyone. “There is nothing so disagreeable, that a patient mind cannot find some solace for it.” by Lucius Annaeus Seneca.
Great post. I just stumbled upon your blog and wanted to say that I have really enjoyed browsing your blog posts. In any case I’ll be subscribing to your feed and I hope you write again soon!
I would like to consider the ability of thanking you for the professional assistance I have enjoyed viewing your site. We are looking forward to the actual commencement of my school research and the whole preparing would never have been complete without checking out your site. If I might be of any help to others, I’d personally be pleased to help by means of what I have gained from here.
Pingback: http://adakemana.com
Wow, incredible blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your site is great, let alone the content!
Very nice design and wonderful articles , hardly anything else we need : D.