关于DAL架构的询问 - 数据集波苏斯 [英] DataSets to POCOs - an inquiry regarding DAL architecture

查看:161
本文介绍了关于DAL架构的询问 - 数据集波苏斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须非常迅速地开发一个相当大的ASP.NET MVC项目,我想获得我的DAL设计的一些意见,以确保没有会回来咬我,因为BL可能得到pretty的复杂。一点背景:我有一个Oracle后端的工作,所以内置的LINQ to SQL是出;我还需要使用生产级库,以便在Oracle EF提供项目超出;最后,我无法使用任何GPL或LGPL code(阿帕奇,MS-PL,BSD也还行),这样的NHibernate /城堡项目都出来了。我想preFER - 如果在所有可能的 - 避免派钱,但我更关心的是实施正确的解决方案。总之,有我的要求:

I have to develop a fairly large ASP.NET MVC project very quickly and I would like to get some opinions on my DAL design to make sure nothing will come back to bite me since the BL is likely to get pretty complex. A bit of background: I am working with an Oracle backend so the built-in LINQ to SQL is out; I also need to use production-level libraries so the Oracle EF provider project is out; finally, I am unable to use any GPL or LGPL code (Apache, MS-PL, BSD are okay) so NHibernate/Castle Project are out. I would prefer - if at all possible - to avoid dishing out money but I am more concerned about implementing the right solution. To summarize, there are my requirements:

  1. 在甲骨文的后端
  2. 在快速发展
  3. (L)GPL自由

  1. Oracle backend
  2. Rapid development
  3. (L)GPL-free

免费

我有理由高兴数据集,但我会受益于使用波苏斯作为数据集和视图之间的媒介。谁知道,也许在某些时候又DAL解决方案将显示出来,我会得到的时间切换出来(是的,没错)。所以,虽然我可以使用LINQ到我的数据集转换为IQueryable的,我想有一个通用的解决方案,所以我不必须写为每个类的自定义查询。

I'm reasonably happy with DataSets but I would benefit from using POCOs as an intermediary between DataSets and views. Who knows, maybe at some point another DAL solution will show up and I will get the time to switch it out (yeah, right). So, while I could use LINQ to convert my DataSets to IQueryable, I would like to have a generic solution so I don't have to write a custom query for each class.

我摆弄思考的权利,但在此期间,我有两个问题:

I'm tinkering with reflection right now, but in the meantime I have two questions:

  1. 是否有我忽略了这个解决方案的任何问题?
  2. 是否还有其他的方法,你会推荐给数据集转换为波苏斯?

在此先感谢。

推荐答案

有没有的正确的答案,但你会发现人谁都会尽力给你一个。有些事情要记住:

There's no correct answer, though you'll find people who will try to give you one. Some things to keep in mind:

  • 既然你不能让EF和LINQ到SQL的优势,不用担心使用IQuerable接口;你将不会得到它的主要优势。当然,一旦你有你的波苏斯,LINQ到对象将与他们打交道的好方法!许多存储库的方法将返回的 的IQueryable< yourType>

只要你有一个很好的来回报您波苏斯,使用反射填写这些是一个好的策略,在第一。 如果你有一个良好的封装库,我再说一遍。您可以随时切换出反射填充实体对象code更有效的code后,并没有在你们BL会知道其中的差别。如果你让自己的依赖的上直反射(不是<一个href="http://darioquintana.com.ar/blogging/2008/07/24/nhibernate-how-much-slow-because-the-use-of-reflection/"相对=nofollow>优化反射像NHibernate的),你可能以后会后悔的低效率。

As long as you have a good repository to return your pocos, using reflection to fill them out is a good strategy, at first. If you have a well-encapsulated repository, I say again. You can always switch out the reflection-filled entity object code for more efficient code later, and nothing in you BL will know the difference. If you make yourself dependent on straight reflection (not optimized reflection like nHibernate), you might regret the inefficiency later.

我会建议寻找到的 T4模板。我生成的实体类(和所有code来填充他们,并坚持他们)从T4模板几个月前,首次。我卖!我的code在我的T4模板是pretty的恐怖这第一次尝试,但它吐出一些的不错的,一致的code。

I would suggest looking into T4 templates. I generated entity classes (and all the code to populate them, and persist them) from T4 templates a few months ago, for the first time. I'm sold! My code in my T4 template is pretty horrible this first try, but it spits out some nice, consistent code.

您必须对您的存储库方法的计划,并密切监察所有的团队创建的方法。你不能有一个一般的 .GetOrders()的方法,因为它会得到的所有的每一次的客户,那么你的LINQ to对象看起来不错,但会涉及一些不好的数据访问!有像 .GetOrderById方法(INT订单ID) .GetOrderByCustomer(INT客户ID)。确保每个返回的实体法在DB使用索引最少。如果基本的查询返回的部分的浪费记录,这很好,但它不能做表扫描和返回的成千上万的浪费记录的。

You will have to have a plan for your repository methods, and closely monitor all the methods your team creates. You can't have a general .GetOrders() method, because it will get all the customers every time, and then your LINQ to object will look nice, but will be covering some bad data access! Have methods like .GetOrderById(int OrderID) and .GetOrderByCustomer(int CustomerID). Make sure each method that returns entities uses an index at least in the DB. If the basic query returns some wasted records, that's fine, but it can't do table scans and return thousands of wasted records.

一个例子:

var Order = From O in rOrders.GetOrderByCustomer(CustID)    
            Where O.OrderDate > PromoBeginDate    
            Select O

在此例中,所有订单客户可能被检索,只是为了得到的一些的订单。但是,不会有大量的浪费,客户ID当然应该在订单索引字段。你必须决定这是否是可以接受的,或者是否一个日期区别添加到您的资料库,无论是作为一种新的方法或重载其他方法。有没有捷径,这一点;你必须走的效率和维护数据抽象之间的界线。你不想在你的仓库里的方法为您的整个解决方案的每一个数据的查询。

In this example, all the Order for a customer would be retrieved, just to get some of the orders. But there won't be a huge amount of waste, and CustomerID should certainly be an indexed field on Orders. You have to decide whether this is acceptable, or whether to add a date distinction to your repository, either as a new method or with overloading other methods. There's no shortcut to this; you have walk the line between efficiency and maintaining your data abstraction. You don't want to have a method in your repository for every single data inquiry in your entire solution.

最近的一些文章,我发现那里的人都绞尽脑汁地究竟是如何做到这一点:

Some recent articles I've found where people are wrestling with how exactly to do this.:

  • http://mikehadlow.blogspot.com/2009/01/should-my-repository-expose-iqueryable.html
  • http://www.west-wind.com/WebLog/posts/160237.aspx

这篇关于关于DAL架构的询问 - 数据集波苏斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆