【问题标题】:DbDomainService<T> does not generate proxy entitiesDbDomainService<T> 不生成代理实体
【发布时间】:2012-05-02 04:55:07
【问题描述】:

我在 Visual Studio 2010 和 11 beta 上都试过这个,在几台机器上。我还使用过 EF 4.3 和 5.0 - beta 2。我正在 silverlight 5 中尝试代码优先方法。

我创建了一个 DbDomainService 并为其创建了 CRUD 操作,但在客户端没有创建代理实体。我在 WCF 类库中执行此操作。以下是它的创建方式:我将一个项目添加到解决方案(WCF RIA 服务类库)。客户端和服务端项目会自动添加并通过 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);
      }
   }
}

【问题讨论】:

    标签: wcf entity-framework ef-code-first ria code-first


    【解决方案1】:

    我为任何好奇的人找到了答案。 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>
    

    只需将其添加到您的 Web.config 文件中,或者如果使用 Ria 服务类库,请将其添加到 app.config 并将 app.config 重命名为 web.config。

    这里是文章的链接:Code project Article

    【讨论】:

    • 我认为我可以在这个问题上浪费 DAYS 天,但你的帖子救了我!非常感谢!
    【解决方案2】:

    我也遇到了 RIA 和 EF 的问题,解决方法是使用 NuGetPackage RIAServices.EntityFramework。问题是,RIA 服务仅支持某些版本的 EF。目前,它看起来只支持

    【讨论】:

    • 跛脚。自 4.1 以来已经发布了 4 个版本并且他们没有更新 RIA?惊奇。看起来我将使用普通的域服务并在幕后创建自己的 DbContext。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-10
    • 2012-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多