<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Do you really need a data access layer with LINQ?</title>
	<atom:link href="http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html</link>
	<description>Productive software development using ASP.NET, C#, Adobe Flex, and other technologies and tools.</description>
	<pubDate>Sat, 22 Nov 2008 04:54:50 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Pay Day Loans</title>
		<link>http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-577</link>
		<dc:creator>Pay Day Loans</dc:creator>
		<pubDate>Tue, 08 Jul 2008 07:03:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-577</guid>
		<description>&lt;strong&gt;Pay Day Loans...&lt;/strong&gt;

...</description>
		<content:encoded><![CDATA[<p><strong>Pay Day Loans&#8230;</strong></p>
<p>&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dew Drop - May 8, 2008 &#124; Alvin Ashcraft's Morning Dew</title>
		<link>http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-245</link>
		<dc:creator>Dew Drop - May 8, 2008 &#124; Alvin Ashcraft's Morning Dew</dc:creator>
		<pubDate>Thu, 08 May 2008 13:16:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-245</guid>
		<description>[...] Do You Really Need a Data Access Layer with LINQ? (Jason Young) [...]</description>
		<content:encoded><![CDATA[<p>[...] Do You Really Need a Data Access Layer with LINQ? (Jason Young) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: teedyay</title>
		<link>http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-243</link>
		<dc:creator>teedyay</dc:creator>
		<pubDate>Thu, 08 May 2008 09:49:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-243</guid>
		<description>Mmm, thanks for the popcorn, Will! ;-)

There's some quite strong opinions on this page, but I can see where you're coming from: LINQ makes it so damn easy to write queries in the code behind your page, but something makes me feel a little uncomfortable doing that.

Just lately I've been trying to put most (all?) of the DB-accessing LINQ queries into the non-generated half of my DataContext class, just so it's all together in one place, giving me my data access layer.

This is fine for encapsulation, but feels a bit like over-engineering when it's a simple query I only use on one page.

LINQ's DataContext has been quite a paradigm shift for me in terms of how I use ORM. For me at least, the jury's still out on issues like this.</description>
		<content:encoded><![CDATA[<p>Mmm, thanks for the popcorn, Will! <img src='http://www.ytechie.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>There&#8217;s some quite strong opinions on this page, but I can see where you&#8217;re coming from: LINQ makes it so damn easy to write queries in the code behind your page, but something makes me feel a little uncomfortable doing that.</p>
<p>Just lately I&#8217;ve been trying to put most (all?) of the DB-accessing LINQ queries into the non-generated half of my DataContext class, just so it&#8217;s all together in one place, giving me my data access layer.</p>
<p>This is fine for encapsulation, but feels a bit like over-engineering when it&#8217;s a simple query I only use on one page.</p>
<p>LINQ&#8217;s DataContext has been quite a paradigm shift for me in terms of how I use ORM. For me at least, the jury&#8217;s still out on issues like this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: superjason</title>
		<link>http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-242</link>
		<dc:creator>superjason</dc:creator>
		<pubDate>Thu, 08 May 2008 01:35:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-242</guid>
		<description>"Eventually you’ll come to the realization that common linq queries belong in a common class accessed by all pages" - I agree, but what I've seen, at least on the last site, common queries are more rare than I would like. Each page usually has different requirements. When I'm writing code, I'm very conscious of rewriting the same functionality. When that happens, of course I'm going to try to re-use my code.

Chad, I agree. I think I've unsuccessfully conveyed the situation that I've run into. I've tried to apply my background in large application development, to individual pages with their own unique functionality. I don't regret insulting people, since I was including myself in that group. I'm simply suggesting that a hard and fast rule of trying desperately to separate out DAL logic might not reap the benefits we would expect. 

In the site I just created, I had all the layers, and they were completely separated. I was able to test any layer regardless of the other layers. The site is reliable thanks to 700 unit tests, but at the expense of having 10x as much code to maintain. Am I really better off? I'm not so sure!

Honestly, I would have rather saved all of that time, and spent it on the critical pages. For example, I would have liked to had a full MVC unit testable checkout process.</description>
		<content:encoded><![CDATA[<p>&#8220;Eventually you’ll come to the realization that common linq queries belong in a common class accessed by all pages&#8221; - I agree, but what I&#8217;ve seen, at least on the last site, common queries are more rare than I would like. Each page usually has different requirements. When I&#8217;m writing code, I&#8217;m very conscious of rewriting the same functionality. When that happens, of course I&#8217;m going to try to re-use my code.</p>
<p>Chad, I agree. I think I&#8217;ve unsuccessfully conveyed the situation that I&#8217;ve run into. I&#8217;ve tried to apply my background in large application development, to individual pages with their own unique functionality. I don&#8217;t regret insulting people, since I was including myself in that group. I&#8217;m simply suggesting that a hard and fast rule of trying desperately to separate out DAL logic might not reap the benefits we would expect. </p>
<p>In the site I just created, I had all the layers, and they were completely separated. I was able to test any layer regardless of the other layers. The site is reliable thanks to 700 unit tests, but at the expense of having 10x as much code to maintain. Am I really better off? I&#8217;m not so sure!</p>
<p>Honestly, I would have rather saved all of that time, and spent it on the critical pages. For example, I would have liked to had a full MVC unit testable checkout process.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chad Myers</title>
		<link>http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-241</link>
		<dc:creator>Chad Myers</dc:creator>
		<pubDate>Wed, 07 May 2008 23:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-241</guid>
		<description>@superjason: Stop insulting people (re: hammer/nail) and try to consider why the 'db.Orders' might be a problem if you ever wanted to use that code against something other than a database (i.e. test data). If you're happy with tightly binding all your code to your database and sure that you'll never re-use that code for anything else, then why do any layers and just have one solid layer and put everything in the code behind or directly in the view?</description>
		<content:encoded><![CDATA[<p>@superjason: Stop insulting people (re: hammer/nail) and try to consider why the &#8216;db.Orders&#8217; might be a problem if you ever wanted to use that code against something other than a database (i.e. test data). If you&#8217;re happy with tightly binding all your code to your database and sure that you&#8217;ll never re-use that code for anything else, then why do any layers and just have one solid layer and put everything in the code behind or directly in the view?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: logicalmind</title>
		<link>http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-240</link>
		<dc:creator>logicalmind</dc:creator>
		<pubDate>Wed, 07 May 2008 22:17:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-240</guid>
		<description>It all depends on project size. If you are a single developer writing all the code and all the pages then of course it's going to be easiest for you to write the least amount of code. Once you introduce more developers to the project that starts to fall apart. 

Are you suggesting that whoever is writing a page determine what linq queries they use and just write those in their page? Eventually you'll come to the realization that common linq queries belong in a common class accessed by all pages. Separate people can write these separate layers as would be the case in projects with more than one developer. Once you do this you're back to where you started except you've replaced nhibernate data access layer with linq for sql data access layer.</description>
		<content:encoded><![CDATA[<p>It all depends on project size. If you are a single developer writing all the code and all the pages then of course it&#8217;s going to be easiest for you to write the least amount of code. Once you introduce more developers to the project that starts to fall apart. </p>
<p>Are you suggesting that whoever is writing a page determine what linq queries they use and just write those in their page? Eventually you&#8217;ll come to the realization that common linq queries belong in a common class accessed by all pages. Separate people can write these separate layers as would be the case in projects with more than one developer. Once you do this you&#8217;re back to where you started except you&#8217;ve replaced nhibernate data access layer with linq for sql data access layer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: superjason</title>
		<link>http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-239</link>
		<dc:creator>superjason</dc:creator>
		<pubDate>Wed, 07 May 2008 21:47:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-239</guid>
		<description>Our business objects match our database. It was written from the ground up that way. We use OR-mappers exclusively.

Code changes will trigger compile errors (when using Linq), and we'll know where to make the changes.

I'll check out the Linq screencast you mentioned. I would like to see a good ecommerce example.</description>
		<content:encoded><![CDATA[<p>Our business objects match our database. It was written from the ground up that way. We use OR-mappers exclusively.</p>
<p>Code changes will trigger compile errors (when using Linq), and we&#8217;ll know where to make the changes.</p>
<p>I&#8217;ll check out the Linq screencast you mentioned. I would like to see a good ecommerce example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paco</title>
		<link>http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-238</link>
		<dc:creator>Paco</dc:creator>
		<pubDate>Wed, 07 May 2008 21:40:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-238</guid>
		<description>The main point is that the structure of your business objects is not the same as the structure of your database in 90% of the situations. And if the structure is the same now, you probably don't want to change the UI code after every minor change in the database. Of course you can solve this problem by writing the Linq XML or [attributes] yourself instead of using the designer, but then you are back to the same difficulties as when you used NHibernate.

The main point about Linq is the delayed execution.
Have you seen the screencast of Rob Conery?
He has a nice way to seperate those things and also uses an ecomerce site as example.

I have also tried Rails. A dissapoint was I have to write 3 times more unit test then in C#, because a compiler already checks a lot of stuff.</description>
		<content:encoded><![CDATA[<p>The main point is that the structure of your business objects is not the same as the structure of your database in 90% of the situations. And if the structure is the same now, you probably don&#8217;t want to change the UI code after every minor change in the database. Of course you can solve this problem by writing the Linq XML or [attributes] yourself instead of using the designer, but then you are back to the same difficulties as when you used NHibernate.</p>
<p>The main point about Linq is the delayed execution.<br />
Have you seen the screencast of Rob Conery?<br />
He has a nice way to seperate those things and also uses an ecomerce site as example.</p>
<p>I have also tried Rails. A dissapoint was I have to write 3 times more unit test then in C#, because a compiler already checks a lot of stuff.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: superjason</title>
		<link>http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-237</link>
		<dc:creator>superjason</dc:creator>
		<pubDate>Wed, 07 May 2008 19:33:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-237</guid>
		<description>Maybe I'm just not understanding, but consider the following query:

var orders = from order in db.Orders
where order.Type == 5
select order;

How can it possibly be beneficial to move that into a data access layer?

I probably should have described the scenario a little better. This is an e-commerce site that has dozens of pages, and they all work quite differently. I've bought into the whole layered approach, defining a data model, using NHibernate, etc. I live it every day. I get frustrated when a page with 4 drop down lists takes 5-10 hours because I have to do this:
- Create my NHibernate queries in my data access layer
- Write unit tests for those queries
- Call those DAL queries from the UI (with the hundreds of other queries in there)
- Debug it if it doesn't work

Then, I have to do it all again to save it. There is SO much code I now have to maintain, and I don't see how it's worth it.

How can replacing 20 lines of code with 3 lines of LINQ not be beneficial? I can write the 3 lines of code in 30 seconds, and test it in another 30. That gives me time to make my DAL better for the times when I actually need it.

As I mentioned, this probably doesn't apply to non-trivial examples.

The point is that some people seem to be too stuck in their old ways of thinking. My background is in enterprise applications, but the simplicity of some of the RoR and DJango code made me jealous, and opened my eyes.

When you have a hammer, everything looks like a nail.</description>
		<content:encoded><![CDATA[<p>Maybe I&#8217;m just not understanding, but consider the following query:</p>
<p>var orders = from order in db.Orders<br />
where order.Type == 5<br />
select order;</p>
<p>How can it possibly be beneficial to move that into a data access layer?</p>
<p>I probably should have described the scenario a little better. This is an e-commerce site that has dozens of pages, and they all work quite differently. I&#8217;ve bought into the whole layered approach, defining a data model, using NHibernate, etc. I live it every day. I get frustrated when a page with 4 drop down lists takes 5-10 hours because I have to do this:<br />
- Create my NHibernate queries in my data access layer<br />
- Write unit tests for those queries<br />
- Call those DAL queries from the UI (with the hundreds of other queries in there)<br />
- Debug it if it doesn&#8217;t work</p>
<p>Then, I have to do it all again to save it. There is SO much code I now have to maintain, and I don&#8217;t see how it&#8217;s worth it.</p>
<p>How can replacing 20 lines of code with 3 lines of LINQ not be beneficial? I can write the 3 lines of code in 30 seconds, and test it in another 30. That gives me time to make my DAL better for the times when I actually need it.</p>
<p>As I mentioned, this probably doesn&#8217;t apply to non-trivial examples.</p>
<p>The point is that some people seem to be too stuck in their old ways of thinking. My background is in enterprise applications, but the simplicity of some of the RoR and DJango code made me jealous, and opened my eyes.</p>
<p>When you have a hammer, everything looks like a nail.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paco</title>
		<link>http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-236</link>
		<dc:creator>Paco</dc:creator>
		<pubDate>Wed, 07 May 2008 19:18:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/do-you-really-need-a-data-access-layer-with-linq.html#comment-236</guid>
		<description>The argument between choosing for a 2 or 3 teer architecture should not be "what framework am I using now?" (linq in this case), but "do I want to implement the some other framework in the future easily?".
When your business objects are all coupled to the data-access layer, you have to rewrite a lot of code when you want to use the futuristic next-gen ORM that is much better then linq five years later. 
I don't understand what unit-testing has to do with this point. Both 2 and 3 teer architectures are testable. You will probably need some more mocking with  2-teer. UI is also testable.</description>
		<content:encoded><![CDATA[<p>The argument between choosing for a 2 or 3 teer architecture should not be &#8220;what framework am I using now?&#8221; (linq in this case), but &#8220;do I want to implement the some other framework in the future easily?&#8221;.<br />
When your business objects are all coupled to the data-access layer, you have to rewrite a lot of code when you want to use the futuristic next-gen ORM that is much better then linq five years later.<br />
I don&#8217;t understand what unit-testing has to do with this point. Both 2 and 3 teer architectures are testable. You will probably need some more mocking with  2-teer. UI is also testable.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
