【问题标题】:Bind data from WCF Ria Services to data grid Entity Framework Code First将数据从 WCF Ria 服务绑定到数据网格实体框架代码优先
【发布时间】:2012-10-25 00:37:13
【问题描述】:

我已经创建了这样的简单 POCO 类:

 public   class Entity
{
 public int   Id { get; set; }
 public bool IsActive { get; set; }
}

这是我的 EF DbContext:

   public class SampleContext:DbContext 
    {
             public DbSet<Entity> Entities { get; set; }

    }

我这样定义示例逻辑层:

       public class EntityTask : IEntityTask 
    {
       #region Implementation of IEntityTask

       public IEnumerable<Entity> GetAll()
       {
           var contex = new SampleContext();

           return contex.Entities.ToList();
       }

       #endregion
    }

     public   interface IEntityTask
 {
     IEnumerable<Entity> GetAll();

 }

这是在服务器项目中定义的 DomainService 类:

    [EnableClientAccess()]
public class CrudService : DomainService
{
    private readonly IEntityTask _entityTask;

    public CrudService(IEntityTask entityTask)
    {
        _entityTask = entityTask;
    }

    public IQueryable<Entity>  GetAll ()
    {
       return _entityTask.GetAll().AsQueryable();
    }
}

完成这些步骤后,我不知道如何在 silverlight 项目中将数据绑定到 DataGrid。 我检查了网络上的许多链接,但其中许多使用向导将数据绑定到数据网格。 如何将实体绑定到 DataGrid ?

【问题讨论】:

    标签: silverlight entity-framework data-binding ef-code-first wcf-ria-services


    【解决方案1】:

    开始使用KeyAttribute(可能在 Id 属性上)标记您的实体,然后 您必须向 msbuild 指明如何创建服务的代理对应项(名为 DomainContext):在您的 silverlight 项目中的属性选项卡下
    选择您的“服务器端”项目并构建解决方案。
    客户端将生成一个代理,通过查看客户端项目进行检查(请务必按“在解决方案资源管理器中显示所有文件”并查找类似于下图的内容

    在 Generated_Code 隐藏文件夹下,您将找到您的 DomainContext。 从现在开始,加载和绑定数据应该非常简单。查看 Brad Abrams here 的优秀博文系列,您会找到所需的一切。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-06
      • 1970-01-01
      • 1970-01-01
      • 2014-10-04
      • 2014-04-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多