企业库5 DataReader或数据集 [英] Enterprise Library 5 DataReader or Dataset

查看:77
本文介绍了企业库5 DataReader或数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Enterprise Library 5从数据库中检索数据。这里我的问题是

我保留了一个文件夹Business Objects。当我检索数据时,我想将这些参数绑定到Business对象。这是我的代码。

IN BO。

Products.cs

I want to retrieve data from database using Enterprise Library 5. Here my problem is
i kept one folder Business objects. when i am retrieving data i want to bind those parameters to Business objects. here is my code.
IN BO.
Products.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BO
{
    public class Products : IProducts
    {
        int _productid; string _productname; int _supplierid; int _unitprice; int _categoryid;

        public int productid
        {
            get
            {
                return _productid;
            }
            set
            {
                _productid = value;
            }
        }

        public string productname
        {
            get
            {
                return _productname;
            }
            set
            {
                _productname = value;
            }
        }

        public int supplierid
        {
            get
            {
                return _supplierid;
            }
            set
            {
                _supplierid = value;
            }
        }

        public int unitprice
        {
            get
            {
                return _unitprice;
            }
            set
            {
                _unitprice = value;
            }
        }

        public int categoryid
        {
            get
            {
                return _categoryid;
            }
            set
            {
                _categoryid = value;
            }
        }
    }
}





DAL如何绑定数据请帮助我谢谢。



IN DAL how can i bind the data please help me thank you.

推荐答案

有很多选项将BO映射到我使用的主要数据库模式,大致按照完成时间的相反顺序:



There are many options map BO onto database schemas the main ones I have used, roughly in reverse order of time taken to complete:



  1. 手动转换器,它采用数据集/阅读器并将它们转换为单独的对象类型。显然,datareader不适合更新。
  2. 编写自己的映射框架。你如何处理这个问题只是涉及到istelf中的一个主题,但是你可以用类来修饰类和持久化字段,这些属性定义了如何将信息输入/输出数据库并编写DAL内容来支持它
  3. 使用现有的ORM框架。 .NET有.net 3.5 SP1的实体框架,但我只是认真地建议.net 4.0 +因为第一个EF版本很差。您也可能会发现EF的性能问题(尽管您可以对此做些事情)并且如果您首先使用数据库,则需要一个规范化的数据库。另一件可能适合LINQ to SQL的法案,它受到支持(许多人认为它不是:它们没有为它开发新的功能,尽管它具有非常完整的功能集)。最后有nHibernate,我多年没用过了,但是当我这么做的时候你必须知道你的东西才能正确映射。

  1. Hand roll converters that take the dataset/ reader and convert them to / from indivdual object types. Obviously the datareader is no good for updates.
  2. Write your own mapping framework. How you go about this is a little involved and a topic in istelf, but you can decorate the class and persisted fields with attributes that define how to get the information in/out of the database and write DAL stuff to support it
  3. Use an existing ORM framework. .NET has the Entity Framework for .net 3.5 SP1, but I''d only suggest it seriously for .net 4.0 + as the first EF version was poor. You also may find perfomance issues with EF (though you can do things about this) and it requires a well normalised database, if you are starting with database first. Another thing that might fit the bill in LINQ to SQL, it is supported (many people think it is isn''t: they are not developing new features for it, though it has a pretty complete features set). Finally there is nHibernate, which I haven''t used for years, but when I did you had to know your stuff to get the mapping right.





选项2& 3将而不是选项i你有一个低复杂度的小OM。选项2可能会变得相当复杂,但值得做的就是练习,因为你可以看到ORM设计师必须面对的挑战。除非你不能从已有的ORM框架中得到你需要的东西,否则我不会建议它用于专业系统。



我的建议是给予尝试Enity Framework:您可以从数据库生成对象模型(假设良好的规范化)或从对象模型生成DB模式(具有良好的规范化,假设正确的对象模型)。如果遇到性能问题,可以预先编译查询并使用存储过程,这样就可以解决这些问题。



Options 2&3 will be slower than option i you have a small OM with low complexity. Option 2 can get quite complicated, but is worth doing as an exercise as you get to see the challanges an ORM designer has to face. I wouldn''t suggest it for a professional system unless you couldn''t get what you need from a pre-existing ORM framework.

My suggestion is to give the Enity Framework a try: you can generate an object model from the database (assuming good normalisation) or generate the DB schema from the Object Model (with good normalisation, assuming a correct object model). If you have performance problems you can pre-compile queries and use stored procedures, so these can be worked around.


这篇关于企业库5 DataReader或数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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