现在的位置: 首页 > 综合 > 正文

XPO – (Gary’s post)Stored Procedure Support Coming in V2010 Vol 2 Part1

2013年03月06日 ⁄ 综合 ⁄ 共 4875字 ⁄ 字号 评论关闭

原文:http://community.devexpress.com/blogs/garyshort/archive/2010/09/22/xpo-stored-procedure-support-coming-in-v2010-vol-2.aspx

XPO – Stored Procedure Support Coming in V2010 Vol 2 --Part 1

Unless you work in a very small software shop, or are a ‘one man band’, the chances are you don’t ‘own’ the data that you are trying to connect to. Between you and it there will normally be a DBA. You know the type, a big burly bruiser of a guy, telling you ‘if your name ain’t on the list you ain’t getting in’. You have to get passed this ‘gatekeeper’ if you want to access any of ‘his’ data. Because of this, any good ORM tool has to have ‘out of the box’ support for stored procedures, and I’m delighted to say that, as of V10.2, XPO will have this support.
除非你在一家很小的软件商店工作,或者在一个个体中,很多情况下你不连接到自己的数据。你和它之间通常会有一个数据库管理员。你知道的类型,一个人高马大的家伙,告诉你,如果你的名字不在他的名单上你就不能进入。如果你要访问他的任何数据,你就不得不通过他的认证。正因如此,任何好的ORM工具不得不支持存储过程,我非常高兴的说,在V10.2版中,XPO将支持存储过程。

With the new release there’ll be two ways of working with stored procedures in XPO:
随着新版发布,在XPO中,将有两种方法支持存储过程:

  1. Direct calling of existing stored procedures and the ability to handle returned data;
    直接调用已存在的存储过程,能处理返回数据;

  2. Mapping of persistent classes on views in the database with help of INSTEAD-OF triggers and stored procedures.
    用数据库中视图持映射久类代替触发器和存储过程。

I guess most people will be using the first variant, so let’s go ahead and check out how that’ll work. Firstly, two methods have been introduced into the Session class:
我猜,大多数人将用第一种方式,因此,让我们继续,看看,那将如何工作。首先,在会话类中介绍两个方法

  1. Selected Data ExecuteSproc(string sprocName, params OperandValue[] parameters), where sprocName is the name of the stored procedure you wish to execute and parameters are the parameters you wish to pass to this stored procedure. This method returns the result in a SelectedData instance.
    选择数据ExecuteSproc(string sprocName, params OperandValue[] parameters),参数sprocName:你要执行的存储过程名称,parameters:你要执行的存储过程的参数。这个方法返回的结果在SelectedData实例中。

  2. ICollection<T> GetObjectsFromSproc<T>(string sprocName, params OperandValue[] parameters).
    This method enables you to load data returned by the stored procedure into non-persistent classes.
    这个方法能使你给非持久类加载存储过程返回的数据。

The Persistent Class Wizard has been extended to help you out when working with stored procedures. So let’s take a look at that now:
已扩展这个持久类向导,帮助你在工作中使用存储过程。因此,现在让我们看看。

To use the Wizard choose the Add New Item command:
要使用向导,选择Add New Item命令:


Then select the Persistent Classes 10.2 item template, change the file name as required and press Add, specify the connection information and hit next
然后,选择Persistent Classes 10.2项目模板,更改为你需求的文件名称并按Add,指定连接信息并点next

In the next step, the wizard displays a list of tables and their columns that can be mapped to persistent objects. We will select the EmployeeSplit table (just for demo purposes) and then press Next:
在接下了一步,向导显示一个表的列表和他们的列,能被映射为持久对象。我们将选择EmployeeSplit表,然后按Next:

Now select the stored procedures we interested in, and select the required columns that will be included in the result set returned by stored procedure then press Finish.
现在,选择我们感兴趣的存储过程,并选择所需的列,将包括在存储过程返回的结果集,然后按Finish

In this example we will choose the CustOrdersOrders stored procecdure, which will return the OrderID, OrderDate, RequireDate, ShippedDate columns. Just for this demo we won’t include the ShippedDate column. After we press Finish, the wizard will generate the following code:

在这个例子中,我们将选择CustOrdersOrders存储过程,将返回OrderID,OrderDate,RequireDate,ShippedDate列。正由于这个演示,我们不包括ShippedDate列。我们按Finsish后,向导生成下面代码:

 

using System;

using DevExpress.Xpo;

namespace Northwind {

    [Persistent("EmployeeSplit_xpoView")]

    public class EmployeeSplit : XPLiteObject {

        int fID;

        [Key]

        public int ID {

            get { return fID; }

            set { SetPropertyValue<int>("ID", ref fID, value); }

        }

        string fExtension;

        [Size(4)]

        public string Extension {

            get { return fExtension; }

            set { SetPropertyValue<string>("Extension", ref fExtension, value); }

        }

        string fPhotoPath;

        [Size(255)]

        public string PhotoPath {

            get { return fPhotoPath; }

            set { SetPropertyValue<string>("PhotoPath", ref fPhotoPath, value); }

        }

        public EmployeeSplit(Session session) : base(session) { }

        public EmployeeSplit() : base(Session.DefaultSession) { }

        public override void AfterConstruction() { base.AfterConstruction(); }

    }

 

    [NonPersistent]

    public class CustOrdersOrders : PersistentBase {

        int fOrderID;

        public int OrderID {

            get { return fOrderID; }

            set { SetPropertyValue<int>("OrderID", ref fOrderID, value); }

        }

        DateTime fOrderDate;

        public DateTime OrderDate {

            get { return fOrderDate; }

            set { SetPropertyValue<DateTime>("OrderDate", ref fOrderDate, value); }

        }

        DateTime fRequiredDate;

        public DateTime RequiredDate {

            get { return fRequiredDate; }

            set { SetPropertyValue<DateTime>("RequiredDate", ref fRequiredDate, value); }

        }

        public CustOrdersOrders(Session session) : base(session) { }

        public CustOrdersOrders() : base(Session.DefaultSession) { }

        public override void AfterConstruction() { base.AfterConstruction(); }

    }

    public static class NorthwindSprocHelper {

 

        public static DevExpress.Xpo.DB.SelectedData ExecCustOrdersOrders(Session session, string CustomerID){

            return session.ExecuteSproc("CustOrdersOrders", CustomerID);

        }

抱歉!评论已关闭.