Silverlight 4 和存储过程

发布于 2024-10-01 01:34:28 字数 206 浏览 0 评论 0原文

经过一天的研究和测试,我得到的印象是您无法使用 WFC RIA 服务从 silverlight 4 调用存储过程。

这根本不可能是真的。

由于 Silverlight 非常注重报告,我不认为没有办法调用存储过程。

您可以将存储过程与 Silverlight 和 RIA 服务一起使用吗?

如果没有,是否有聚合数据集的解决方法>?

After a day of research and testing I am getting the impression that you cannont call stored procedures from silverlight 4 using WFC RIA services.

This simply cannot be true.

With Silverlight being very report focused I don't believe there is no way to call stored procedures.

Can you use Stored Procedures with Silverlight and RIA services ?

If not is there a workaround for aggregate data sets >?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌伤ぢ 2024-10-08 01:34:28

您必须将其作为函数添加到模型中,然后作为 DomainService 的成员调用它。关键在于存储过程结果必须精确映射到实体,因为 RIA 服务不允许您使用复杂类型结果。

还可以不使用 RIA 并使用支持 Silverlight 的 WCF 服务。但是,您将失去所有 DomainService 功能(例如 LINQ),但您可以更好地控制返回内容以及返回方式。

You must add it to your model as a function and then invoke it as a member of the DomainService. The kicker is that the stored procedure result must exactly map up to an entity because RIA services won't allow you to use a complex type result.

There is also the possibility of not using RIA and using a Silverlight-enabled WCF service. However, you will lose all the DomainService functionality like LINQ, but you get more control over what is being returned and how.

<逆流佳人身旁 2024-10-08 01:34:28

我在此站点上找到了以下出色的分步指南 -

http:// betaforums.silverlight.net/forums/p/218383/521023.aspx

1) 将 ADO 实体数据模型添加到您的 Web 项目;选择从数据库生成选项;选择要连接的数据库实例。

2) 选择要导入模型的数据库对象。您可以展开表节点以选择要导入模型的任何表。展开存储过程节点以选择您的存储过程。单击“完成”完成导入。

3) 右键单击​​数据库模型设计器,选择添加/函数导入。为函数命名(与 SP 名称相同即可)并选择要映射的存储过程。如果您的 SP 仅返回一个字段,您可以将返回结果映射到一组标量。如果您的 SP 返回多个字段,您可以将返回结果映射到集合或实体(如果所有字段都来自单个表)或复杂类型的集合。

如果您想使用复杂类型,您可以单击获取列按钮来获取 SP 的所有列。然后单击“创建新的复杂类型”按钮来创建此复杂类型。

4) 将Domain Service 类添加到Web 项目中。选择您刚刚创建的 DataModel 作为此服务的 DataContext。选择您想要向客户端公开的所有实体。应该为这些实体生成服务功能。

5) 您可能在实体列表中看不到 Complex 类型。您必须在您的 Service 中手动添加 SP 的查询功能:
假设您的 SP 称为 SP1,则生成的 Complex 类型称为 SP1_Result。

在您的域服务类中添加以下代码:

public IQueryable<SP1_Result> SP1()
    {
        return this.ObjectContext.SP1().AsQueryable();            
    }

现在您可以编译您的项目了。您可能会收到如下错误:“SP1_Result 没有密钥”(如果您没有使用 RIA 服务 SP1 beta)。如果这样做,您需要在服务元数据文件中执行以下操作:

添加 SP1_Result 元数据类并标记 Key 字段:

[MetadataTypeAttribute(typeof(SP1_Result.SP1_ResultMetadata))]
public partial class SP1_Result
{
    internal sealed class SP1_ResultMetadata
    {
        [Key]
        public int MyId;  // Change MyId to the ID field of your SP_Result
    }
} 

6) 编译您的解决方案。现在您已将 SP1_Result 暴露给客户端。检查生成的文件,您应该看到 SP1_Result 生成为实体类。现在您可以在 Silverlight 代码中访问 DomainContext.SP1Query 和 DomainContext.SP1_Results。您可以像对待任何其他实体(映射到表的实体)类一样对待它。

I found the following excellent step-by-step guide at this site -

http://betaforums.silverlight.net/forums/p/218383/521023.aspx

1) Add a ADO Entity Data Model to your Web project; Select generate from database option; Select your Database instance to connect to.

2) Choose your DB object to import to the Model. You can expand Table node to select any table you want to import to the Model. Expand Stored Procedure node to select your Stored Precedure as well. Click Finish to finish the import.

3) Right click the DB model designer to select Add/Function Import. Give the function a name (same name as your SP would be fine) and select the Stored Procedure you want to map. If your SP returns only one field, you can map the return result to a collection of scalars. If your SP returns more than one field, you could either map the return result to a collection or Entity (if all the field are from a single table) or a collection of Complex types.

If you want to use Complex type, you can click Get Column button to get all the columns for your SP. Then click Create new Complex type button to create this Complex type.

4) Add a Domain Service class to the Web project. Select the DataModel you just created as the DataContext of this Service. Select all the entitis you want expose to the client. The service functions should be generated for those entities.

5) You may not see the Complex type in the Entity list. You have to manully add a query function for your SP in your Service:
Say your SP is called SP1, the Complex type you generated is called SP1_Result.

Add the following code in your Domain Service class:

public IQueryable<SP1_Result> SP1()
    {
        return this.ObjectContext.SP1().AsQueryable();            
    }

Now you can compile your project. You might get an error like this: "SP1_Result does not have a Key" (if you not on RIA service SP1 beta). If you do, you need to do the following in the service metadata file:

Added a SP1_Result metadata class and tagged the Key field:

[MetadataTypeAttribute(typeof(SP1_Result.SP1_ResultMetadata))]
public partial class SP1_Result
{
    internal sealed class SP1_ResultMetadata
    {
        [Key]
        public int MyId;  // Change MyId to the ID field of your SP_Result
    }
} 

6) Compile your solution. Now you have SP1_Result exposed to the client. Check the generated file, you should see SP1_Result is generated as an Entity class. Now you can access DomainContext.SP1Query and DomainContext.SP1_Results in your Silverlight code. You can treat it as you do with any other Entity(the entity mapped to a table) class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文