开发者

Ria Services. Loading object with dependencies via Invoke method

开发者 https://www.devze.com 2023-02-03 19:31 出处:网络
How can I load object with dependencies via Invoke method? E.g. I have a DTO: [DataContract] public class MyDTO

How can I load object with dependencies via Invoke method?

E.g. I have a DTO:

[DataContract]

public class MyDTO

{

[DataMember]public int Id{get;set;}

[DataMember] public string SomeField {get;set;}

[DataMember][Include]public IList< SomeEntity > Dependencies {get;set} }

And invoke method:

[Invok开发者_开发技巧e]

public MyDTO GetDTO()

{

return new MyDTO() { Id=1, SomeFields="Test", Dependencies=new List< SomeEntity >(){new SomeEntity()}; }

In this case on client side I can attach MyDTO instance to main domain context, but Dependencies don't load. I don't want to create new method to get Dependencies separatelly.If create query method instead invoke I should work with IEnumerable but I need only one instance. What is the best way to resolve that? Thanks.


If create query method instead invoke I should work with IEnumerable but I need only one instance. What is the best way to resolve that? Thanks.

Via LINQ when you query your Context and asking for the first record (there will be only one or none if it's your PK you're querying by):

Context.Load(Context.GeEmployeeQuery().Where(a => a.EmployeeId == employeeId),
                                LoadBehavior.RefreshCurrent,
                                x =>
                                  {
                                    Employee = x.Entities.FirstOrDefault();
                                  }, null);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号