开发者

RIA Services linq problem - convert output

开发者 https://www.devze.com 2023-04-03 21:48 出处:网络
I am developing a Silverlight Web application and using RIA services. Part of the code from the Domain Service Class looks like this:

I am developing a Silverlight Web application and using RIA services. Part of the code from the Domain Service Class looks like this:

public IQueryable<ClassA> GetClassa()
{
     return this.ObjectContext.ClassA;
}

This services is than called by one of the views:

SomeContext context = new SomeContext ();
var items = context.Load(context.GetClassaQuery().
            Where(r => some condition).
            Select(r => new ClassB(
             //ClassB initialization
            )));

So I want to get all ClassA and based on a criteria create new ClassB which are then going into a Telerik Chart

this._reviewedICs.ItemsSource = items;

The problem is that I can not implicitly convert it from one to another. How can I fix this

开发者_Go百科Edit: Totaly forgot that 'Load()' has a 'Completed' event -_- After the event is fired i just handle it in the event handler

context.Load(context.GetClassaQuery()).Completed(DoSomething)
private void DoSomething(object sender, EventArgs e)
{
    List<ClassA> = context.ClassA.ToList();
    //do whatever you want :)
}


Here is an example of how to do it:

List<ClassB> allTheBs;

SomeContext ctx = new SomeContext();

LoadOperation<ClassA> loader = ctx.Load( context.GetClassaQuery().Where(...) );
loader.Completed += (s,e) =>
    {
        var entities = (s as LoadOperation<ClassA>).Entities;

        allTheBs = entities.Select ( a => new ClassB()
                {
                    a.Field1 = b.SomeField,
                    a.Field2 = b.SomeOtherField
                } );
    };
0

精彩评论

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

关注公众号