Jas*_*wer 1 wcf ria entity-framework code-first ef-code-first
我已经在几台机器上的visual studio 2010和11 beta上试过这个.我还使用了EF 4.3和5.0 - beta 2.我正在尝试Silverlight 5中的代码优先方法.
我创建了一个DbDomainService并为它创建了CRUD操作,但在客户端没有创建任何代理实体.我在WCF类库中执行此操作.以下是它的创建方法:我将一个项目添加到解决方案(WCF RIA Services类库).客户端和服务端项目会自动添加并通过RIA链接进行链接.我创建了我的实体和dbcontext(参见下面的源代码).我创建了我的域服务类(向导只显示了一半的时间,非常错误)并确保有CRUD操作.我重建,并在客户端项目上显示所有文件,并且没有生成代码.如果我将DomianService类更改为继承自DomainService而不是DbDomainService,那么我的代理实体将按照预期在客户端生成.
构建解决方案时,我收到以下警告:
警告1创建MEF组合容器时发生以下异常:无法加载一个或多个请求的类型.检索LoaderExceptions属性以获取更多信息.将使用默认代码生成器.AProgram.Client.RIAServices
请帮忙 :)
namespace AProgram.Server.RIAServices.Models.Sales
{
public class Customer
{
[Key]
public int CustomerID { get; set; }
[Required]
[MaxLength(50)]
public string CustomerName { get; set; }
}
}
namespace AProgram.Server.RIAServices
{
public class SalesDbContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
}
}
namespace AProgram.Server.RIAServices
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
// TODO: Create methods containing your application logic.
[EnableClientAccess()]
public class SalesDomainService : DbDomainService<SalesDbContext>
{
[Query(IsComposible=false)]
public Customer GetCustomer(int id)
{
return this.DbContext.Customers.Find(id);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我找到了一个好奇的人的答案.Ria Services似乎只与EF 4.1兼容.我在代码项目文章中找到了一个解决方法:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="EntityFramework"
publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)
只需将其添加到Web.config文件中,或者如果使用Ria Services类库,则将其添加到app.config并将app.config重命名为web.config.
这是文章的链接:代码项目文章
| 归档时间: |
|
| 查看次数: |
1086 次 |
| 最近记录: |