从客户端访问中的DomainService自定义对象 [英] Accessing custom objects in DomainService from client
问题描述
我使用的域名服务,以从Silverlight客户端数据库获取数据。
I am using Domain Service to fetch data from database from Silverlight Client.
在DomainService1.cs,我已经添加了以下内容:
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
}
在DomainService1 I类增加了新的方法,以检索自定义类对象的集合:
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;
}
}
从Silverlight客户端我试图访问方法:
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
但它不是调用新方法的正确方法。我在DomainServices.cs加入了一类新产品的原因是为了有一种有效的分组。使用由实体框架自动生成的模型类我不能达到同样的
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?
推荐答案
虽然我不知道你的意思是这不是调用新方法的正确途径,或者如果您收到任何错误,我想,也许有些张贴工作code可能有帮助。
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.
我的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();
}
}
在域名服务的方法(EnableClientAccess装饰类)
A method in the domain service (EnableClientAccess decorates the class)
public IEnumerable<GraphPointWithMeta> CallingActivityByCommercial()
{
List<GraphPointWithMeta> gps = new List<GraphPointWithMeta>();
// ...
return gps;
}
从Silverlight客户端调用像
Called from the Silverlight client like
ctx1.Load(ctx1.CallingActivityByCommercialQuery(), CallingActivityCompleted, null);
客户端回调方法
private void CallingActivityCompleted(LoadOperation<GraphPointWithMeta> lo)
{
// lo.Entities is an IEnumerable<GraphPointWithMeta>
}
这篇关于从客户端访问中的DomainService自定义对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!