Silverlight 到 RIA 服务到业务对象导致构建错误

发布于 2024-08-10 05:48:35 字数 1359 浏览 0 评论 0原文

我已经完成了与 Silverlight 和 Ria 服务相关的基本教程,现在我正在尝试扩展到我以前使用过的模型。

我有一个 Silverlight 项目,我想使用 Ria 服务。与我见过的 Ria 服务教程不同,我想让我的域服务在保存我的域实体(使用 EF 创建)的业务对象 (DLL) 项目中使用存储库对象。

以下是我正在使用的域服务的示例片段:

[EnableClientAccess()]
public class ContactService : DomainService
{
    public List<Contact> ContactSearch(string lastName)
    {
        ContactRepository rep = new ContactRepository();
        return rep.SearchByLastName(lastName);
    }
}

Contact 和 ContactRepository 位于我的 Business Objects 项目中。 ContactRepository 查询 EF 中的联系人实体。

当我构建时,我收到以下错误:

实体 'SilverlightCRM.BusinessObjects.Contact' 没有定义密钥。实体 由 DomainService 操作公开 必须有 必须有至少一个 用 KeyAttribute 标记的属性。

如果我更改实体生成的代码以使用 System.ComponentModel.DataAnnotation.Key() 属性装饰 Contact.ContactID 属性,如所述 这里,我得到另一个版本包含域服务的项目的 .g.cs 文件中出现错误。

命名空间“数据”的类型不 存在于名称空间“System”中(您是 缺少程序集引用?)

由于 .g.cs 文件是在构建时自动生成的,因此仅注释掉一行是行不通的,而且我将 System.Data 作为项目引用。

我在这里做错了什么?我认为我能够使用这种组织解决方案各个方面的模型,但是如果我想使用 Ria 服务,我是否必须进行更改?

I've went through the basic tutorials associated with Silverlight and Ria Services and I am now trying to branch out to a model I have used before.

I have a Silverlight project that I want to use Ria Services with. Unlike the tutorials for Ria Services that I've seen, I'm wanting to have my Domain Services to use Repository objects in a Business Object (DLL) project that holds my domain entities (created using EF).

Here's an example snippet of a domain service I'm working with:

[EnableClientAccess()]
public class ContactService : DomainService
{
    public List<Contact> ContactSearch(string lastName)
    {
        ContactRepository rep = new ContactRepository();
        return rep.SearchByLastName(lastName);
    }
}

Contact and ContactRepository are in my Business Objects project. ContactRepository queries EF for the Contact Entities.

When I build, I get the following error:

The entity
'SilverlightCRM.BusinessObjects.Contact'
does not have a key defined. Entities
exposed by DomainService operations
must have must have at least one
property marked with the KeyAttribute.

If I change the entity generated code to decorate the Contact.ContactID property with the System.ComponentModel.DataAnnotation.Key() attribute as described here, I get another build error in my <projectname>.g.cs file of my project containing my domain service.

Type of Namespace 'Data' does not
exist in namespace 'System' (are you
missing an assembly reference?)

Since the <projectname>.g.cs file is autogenerated on build, just commenting out a line doesn't work and I have System.Data as a project reference.

What am I doing wrong here? I would think that I'd be able to use this model of organizing aspects of my solution but do I have to change things if I want to use Ria Services?

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

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

发布评论

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

评论(2

雄赳赳气昂昂 2024-08-17 05:48:35

确保您引用 RIA 服务文件夹中的 System.ComponentModel.DataAnnotations dll(其版本为 99.0.0.0)。

Make sure you're referencing the System.ComponentModel.DataAnnotations dll from the RIA services folder (it has a version of 99.0.0.0).

半山落雨半山空 2024-08-17 05:48:35

我发现的问题是,我必须让 Ria 服务从 LinqToEntitiesDomainService 继承,而不仅仅是域服务,因为传递的类型是来自 EF 的实体。

The issue I discovered was that I had to have my Ria Service inherit from LinqToEntitiesDomainService instead of just Domain Service since the types being passed were Entities from EF.

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