Shahin
Shahin

Reputation: 12861

Bind data from WCF Ria Services to data grid Entity Framework Code First

I've created simple POCO class like this :

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

And this is my EF DbContext :

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

    }

I defined sample logic layer like this :

       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();

 }

This is DomainService class that defined in server project :

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

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

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

After these steps I don't know how to bind data to DataGrid in silverlight project. I've checked many links on the web but many of them use wizard to bind data to datagrid. How do I bind entities to DataGrid ?

Upvotes: 0

Views: 523

Answers (1)

mCasamento
mCasamento

Reputation: 1433

Start marking your entity with the KeyAttribute (probably on the Id property) then you must indicate to msbuild how to create the proxy counterpart of your service (named the DomainContext): in your silverlight project under properties tab RiaLink
select your "server side" project and build the solution.
Client side a proxy will be generated, check it by looking in the client project (be sure to press "Show all files in Solution Explorer" and look for something similar to the image below
RiaProxy
Under the Generated_Code hidden folder you'll find your DomainContext. From now on it should be pretty straightforward to load and bind your data. Look at the excellent blog posts series by Brad Abrams here, you'll find everything you need.

Upvotes: 1

Related Questions