跨 RIA 服务共享 Linq to SQL 实体
我正在创建非常薄的 DTO,我想知道是否有一种方法可以共享 Linq-to SQL 实体本身。我试过了。我在部分类中创建了一个元数据类并设置了关键注释。然后我尝试从 RIA 服务公开查询中的实体。尽管在生成的代码中抱怨 System.Data.Linq
,但我遇到了错误。这是有道理的,但是有没有一种方法可以做到这一点,而不需要继承对此库的依赖以及 Silverlight 中不可用的其他库?
请注意,我没有使用实体框架,因为它对于我当前的项目来说太大了。我宁愿使用瘦 DTO,也不愿为这个项目引入 EF。
编辑:
我的问题更普遍的是:LINQ to SQL 实体可以直接用作 RIA 服务 DTO 并由服务共享吗?
I am creating very thin DTO's and I'm wondering if there is a way of sharing the Linq-to SQL entities themselves. I've tried. I created a metadata class inside of a partial class and set the key annotations. Then I tried to expose the entities in a query from my RIA service. I get on error though that complains about System.Data.Linq
in the generated code. This makes sense, but is there a way to do this without carrying over dependencies on this an other libraries not available in Silverlight?
Note, I'm not using the entity framework because it is way to big for my current project. I'd rather use the thin DTO's than bring in EF for this project.
Edits:
My question is more generally this: Can LINQ to SQL entities be used directly as RIA Services DTO's and shared by a service?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短回答:不采取其他方法 否。
详细回答:
Silverlight 运行时表示的 .NET Framework 版本并不支持所有 API。有关支持者 API 的完整列表,请参阅此处:
http://blogs.msdn.com/b/nickkramer/archive/2010/03/19/silverlight-4-rc-api-listing-in-one -big-text-file.aspx
如果您尝试使用任何依赖于不受支持的 API 的 DLL,那么您将遇到所遇到的问题。您无法通过 RIA 线路以原始状态推送 LINQ to SQL 类。
唯一可行的方法是,如果您的 LINQ to SQL 层是针对映射到 DataContext 的 POCO 类生成的,例如以下示例: http://www.thinqlinq.com/default/LINQ-to-SQL-support-for-POCO.aspx
Short answer: without taking another approach No.
Long answer:
Not all APIs are supported in the .NET Framework version that is represented by the Silverlight runtime. For a complete list of supporter APIs see here:
http://blogs.msdn.com/b/nickkramer/archive/2010/03/19/silverlight-4-rc-api-listing-in-one-big-text-file.aspx
If you try to use any DLLs which have a dependency on APIs that are not supported then you will run into the problem you are experiencing. You cannot push over the LINQ to SQL classes across the RIA wire in their raw state.
The only way this would work is if your LINQ to SQL layer were generated against POCO classes that were mapped to a DataContext such as with this example: http://www.thinqlinq.com/default/LINQ-to-SQL-support-for-POCO.aspx