使用实体框架和 RIA 服务的动态数据

发布于 2024-07-25 00:43:39 字数 335 浏览 2 评论 0原文

这个问题是另一个问题的延伸,但我认为它有自己的主题。 请参阅请参阅 Silverlight 问题

我有一个返回动态数据集的存储过程 (SQL 2005) (每次调用时都会有不同的列/模式)。

我想在 Silverlight 3.0 中使用它,因此我需要使用实体框架和 RIA 服务以某种方式连接它。 我还需要它是可绑定的(Silverlight Grid),所以我需要可以通过属性(网格限制)访问这些动态列。 有任何想法吗?

This question is an extension of another question, but I think it warrants its own thread. See See Silverlight Question

I have a stored procedure (SQL 2005) that returns a dynamic data set (different columns/schema) each time it is called.

I want to consume this in Silverlight 3.0 so I need to somehow wire this up using Entity Framework and RIA Services. I also need this to be Bindable (Silverlight Grid) so I need these dynamic columns to be accessible via properties (grid limitation). Any ideas?

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

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

发布评论

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

评论(2

梦屿孤独相伴 2024-08-01 00:43:39

在当前发布的实体框架版本中,您可以映射的唯一存储过程类型是返回实体类型的存储过程类型。 通常,映射是在编译之前完成的,尽管至少理论上可以在运行时生成实体框架元数据。

因此,我看到了一些选择。

  1. 放弃使用不返回已定义模式的过程的整个想法。 在编译之前你永远无法映射这样的过程。
  2. 在运行时动态生成 EDMX,以便在调用之前将实体类型映射到过程的预期输出列。 请注意,当前版本的实体框架对于过程返回的列有点挑剔; 您可以在 MSDN 上找到有关此内容的文档。
  3. 在 .NET 4.0 中,有一些新功能可以让您在运行时向实体框架通知您的客户端架构,而无需先生成 EDMX。 您也许能够利用这些功能将某些实体类型映射到过程的预期输出列。
  4. 同样,在 .NET 4.0 中,可能支持返回标量值的过程。 我不记得是否是这样。
  5. 您始终可以从实体连接获取标准数据库连接,并使用常规 SqlCommand 直接执行过程。 不幸的是,这使得您的代码特定于数据库提供程序,但这可能是解决您的问题的最简单的解决方案。 事实上,使用这样的过程已经是特定于数据库服务器的了。

In the currently shipping version of the Entity Framework, the only type of stored procedures you can map are those which return entity types. The mapping is done, generally, before you compile, although it seems at least theoretically possible to generate Entity Framework metadata at runtime.

Therefore, I see a few choices.

  1. Give up on the whole idea of consuming a procedure which does not return a defined schema. You will never be able to map such a procedure before you compile.
  2. Dynamically generate EDMX at runtime in order to map an entity type to the expected output columns of the procedure before you invoke. Note that the current version of the Entity Framework is a bit finicky about the columns a procedure returns; you can find documentation about this on MSDN.
  3. In .NET 4.0, there are new features which allow you to inform the Entity Framework about your client schema at runtime without having to generate EDMX first. You might be able to leverage these features in order to map some entity type to the expected output columns of the procedure.
  4. Again, in .NET 4.0, there may be support for procs which return scalar values. I can't remember if this is the case or not.
  5. You can always get a standard database connection from the entity connection and execute the procedure directly, using regular SqlCommands. Unfortunately, this makes your code database-provider-specific, but it may be the simplest solution to your problem. Indeed, using such a procedure at all is already database-server-specific.
离旧人 2024-08-01 00:43:39

您可以使用 WCF Web 服务包装器来访问 SP 并使用 WCF 服务作为数据源 Brad Abrams 在其关于 RIA 服务的系列文章中提供了一种方法

You might use a WCF web service wraper for accesing your SP and use the WCF service as data source Brad Abrams has a way to do that on his series of articles on RIA Services

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