New Posts New Posts RSS Feed: Is it possibale to cast a entity into a interface with a linq Query
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Is it possibale to cast a entity into a interface with a linq Query

 Post Reply Post Reply
Author
JJANSSEN View Drop Down
Newbie
Newbie


Joined: 25-Aug-2011
Posts: 10
Post Options Post Options   Quote JJANSSEN Quote  Post ReplyReply Direct Link To This Post Topic: Is it possibale to cast a entity into a interface with a linq Query
    Posted: 25-Aug-2011 at 9:06am
Header of the partial class
 
public partial class Sortiment : IbEm.Entity , IHierarchieElement
 
 
Methode to invoke a query with Linq and Cast it.

 public INotifyCompleted LoadHierarchieStruktur(Action<IEnumerable<IHierarchieElement>> onSuccess, Action<Exception> onFail)
        {
            EntityQueryOperation<IHierarchieElement> op = Manager.Sortiment.Cast<IHierarchieElement>()
                .Where(c => c.GetEbene().Equals("1"))
                .ExecuteAsync();
 
            return op.OnComplete(onSuccess, onFail);
 }
 
I ask because we get an exception:
Unable to locate type: System.Linq.IQueryable`1[[~.IHierarchieElement, Common.SL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e. Check that the assembly holding this type is available in the bin/exe folder. Also check that both your assemblies and DevForce assemblies have the expected version number on both client and server.
 
 
We checked assemblies and do not find the solution :-(.
Code and Fixed Width Data
[CODE]

Code and Fixed Width Data
[CODE]
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 25-Aug-2011 at 5:05pm
Hi Jjanssen,
 
Unfortunatelly this will not be possible.
 
The issue is that the DF don't have enough information to serialize the results back to the client for non-scalar query results. 
It will try to send a List<ICustomer> back to the client, and the serializer doesn't know what a List<ICustomer> is.
So the list form of the query will always fail, for any entity type.
 
Can you elaborate on why you are trying this approach, so I can better understand and assist?
 
Regards,
   Silvio.
Back to Top
JJANSSEN View Drop Down
Newbie
Newbie


Joined: 25-Aug-2011
Posts: 10
Post Options Post Options   Quote JJANSSEN Quote  Post ReplyReply Direct Link To This Post Posted: 26-Aug-2011 at 12:22am
Hi Silvio,

we have an GUI-Componten to display Data in a TreeView. The general Component did not know which Entity are inside in the model but know the entity has the Interface like "IHierarchieElement" with the methode "GetName(), GetNumber()".

We have an idea to find a solution, while we transfor the entity in the GUI into another objekt with the interface "IHierarchieElement". A disadvantage is that it is complex and more code.

Regards,
   Johannes.

Back to Top
JJANSSEN View Drop Down
Newbie
Newbie


Joined: 25-Aug-2011
Posts: 10
Post Options Post Options   Quote JJANSSEN Quote  Post ReplyReply Direct Link To This Post Posted: 30-Aug-2011 at 3:36am
I found a solution in collaboration with Marcel Good:

public INotifyCompleted LoadHierarchieStruktur(Action<IEnumerable<IHierarchieElement>> onSuccess, Action<Exception> onFail)
{
            
            ITypedEntityQuery baseQuery  = Manager.Sortiment.Include("UnterSortimente");
 
            var predicate = PredicateBuilder.Make("Ebene"FilterOperator.IsEqualTo, "1");
            var op = baseQuery.Where(predicate).ExecuteAsync();
            return op.OnComplete(result => { if (onSuccess != null) onSuccess(result.Cast<IHierarchieElement>()); }, onFail);
            
}


An approach for the solution was found in the documentation section.
http://drc.ideablade.com/xwiki/bin/view/Documentation/predicatebuilder-methods

Regards,  Johannes

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down