Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing custom objects in DomainService from client

I am using Domain Service to fetch data from database from Silverlight Client.

In DomainService1.cs, I have added the following:

[EnableClientAccess()]
public class Product
{
    public int productID;
    public string productName;        
    public List<Part> Parts = new List<Part>(); //Part is already present in Model designer
}

In DomainService1 class I added a new method to retrive a collection of the custom class object:

[EnableClientAccess()]
 public class DomainService1 : LinqToEntitiesDomainService<HELPERDBNEWEntities1>
 {
     ...
        public List<Product> GetProductsList(...)
        {
            List<Product> resultProducts = new List<Product>();
            ...
            return resultProducts;
        }
 }

From the silverlight client I am trying to access that method:

DomainService1 ds1 = new DomainService1();
var allproductList = ds1.GetProductsList(...);
ds1.Load<SLProduct>(allproductList).Completed += new EventHandler(Load_Completed); //Not correct usage

However it is not the correct way to call the new method. The reason I added a new class Product in DomainServices.cs is to have an efficient grouping. I cannot achieve the same using the model classes auto-generated by the entity framework.

How call I call the new method from the client?

like image 929
softwarematter Avatar asked Nov 05 '22 07:11

softwarematter


2 Answers

I believe there is a similar question with an answer here:

Can a DomainService return a single custom type?

Also, here is some discussion about the overall problem of adding custom methods in a Domain Service:

http://forums.silverlight.net/t/159292.aspx/1

like image 74
Kyberias Avatar answered Nov 09 '22 04:11

Kyberias


While I don't know what you mean by "it is not the correct way to call the new method", or if you're getting any errors, I thought maybe posting some working code might help.

My POCO

    public class GraphPointWithMeta
{
    [Key]
    public Guid PK { get; set; }
    public string SeriesName { get; set; } 
    public string EntityName { get; set; }
    public double Amount { get; set; }

    public GraphPointWithMeta(string seriesName, string entityName, double amount)
    {
        PK = Guid.NewGuid();
        SeriesName = seriesName;
        EntityName = entityName;
        Amount = amount;
    }

    // Default ctor required.
    public GraphPointWithMeta()
    {
        PK = Guid.NewGuid();
    }
}

A method in the domain service (EnableClientAccess decorates the class)

        public IEnumerable<GraphPointWithMeta> CallingActivityByCommercial()
    {
        List<GraphPointWithMeta> gps = new List<GraphPointWithMeta>();
        // ...
        return gps;
    }

Called from the Silverlight client like

ctx1.Load(ctx1.CallingActivityByCommercialQuery(), CallingActivityCompleted, null);

client call back method

        private void CallingActivityCompleted(LoadOperation<GraphPointWithMeta> lo)
    {
        // lo.Entities is an IEnumerable<GraphPointWithMeta>            
    }
like image 22
Mike Hildner Avatar answered Nov 09 '22 03:11

Mike Hildner