2009-11-06 57 views
2

我已经通过了与Silverlight和Ria服务相关的基本教程,现在我试图分支到我以前使用过的模型。Silverlight到RIA服务到企业对象导致构建错误

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

这里是一个域服务的示例代码段我的工作:

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

联系和ContactRepository都在我的业务对象的项目。 ContactRepository为联系实体查询EF。

当我建,我得到以下错误:

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.

如果我改变实体生成的代码与System.ComponentModel.DataAnnotation.Key()属性来装点Contact.ContactID属性描述here,我再生成错误在我<projectname>.g.cs文件我的项目包含我的域名服务。

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

由于<projectname>.g.cs文件自动生成的身材,只是注释掉行不工作,我有System.Data作为项目参考。

我在这里做错了什么?我认为我可以使用这种模式来组织我的解决方案,但是如果我想使用Ria服务,我是否必须改变这些模式?

回答

0

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

2

确保您引用了RIA services文件夹中的System.ComponentModel.DataAnnotations dll(它的版本为99.0.0.0)。

+0

这样做后,我现在可以单独构建2个项目;然而,如果我构建完整的解决方案,我仍然会遇到错误。思考? (除了单独构建:-)) – JamesEggers 2009-11-07 04:19:15