New Posts New Posts RSS Feed: Include and problem of RelatedEntity<T>
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Include and problem of RelatedEntity<T>

 Post Reply Post Reply
Author
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Topic: Include and problem of RelatedEntity<T>
    Posted: 01-Jun-2012 at 8:20am
Hello Marcel,

var query = entityManagerProvider.Manager.INDICATORI
                     .Include(o1 => o1.SNAPSHOT)
                     .Where(x => x.Dashboards.Any(y => y.ID == idDashboard));
was exacly what I was looking for...I wasn't aware of the any usage in this way so I woudn't succed in!

Thanks a lot!



Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 31-May-2012 at 11:12am
Reading your post again, I'm not sure if you need INDICATORI entities or if you only want the SNAPSHOP entities. If you only want the snapshot entities, then you can do the following:
 

public OperationResult<IEnumerable<SNAPSHOT>> GetSnapshotFromDashboardAsync(int idDashboard, Action<IEnumerable<SNAPSHOT>> onSuccess = null, Action<Exception> onFail = null)

      {

          var query = entityManagerProvider.Manager.INDICATORI

                     .Where(x => x.Dashboards.Any(y => y.ID == idDashboard))
                     .SelectMany(x => x.SNAPSHOT)

 

          var op = query.ExecuteAsync();

 

          return op.OnComplete(onSuccess, onFail).AsOperationResult();

      }

or if you want the SNAPSHOT entities, but also get each associated INDICATORI with it, then you invert the query and start with SNAPSHOT:
 

public OperationResult<IEnumerable<SNAPSHOT>> GetSnapshotFromDashboardAsync(int idDashboard, Action<IEnumerable<SNAPSHOT>> onSuccess = null, Action<Exception> onFail = null)

      {

          var query = entityManagerProvider.Manager.SNAPSHOT

                     .Include(x => x.INDICATORI)
                     .Where(x => x.INDICATOR.Dashboards.Any(y => y.ID == idDashboard));

 

          var op = query.ExecuteAsync();

 

          return op.OnComplete(onSuccess, onFail).AsOperationResult();

      }

Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 31-May-2012 at 10:42am
Oh, sorry, didn't notice you had a many-to-many there. So, let's try again. INDICATORI should have a Dashboards related entity list, again not sure what you called the property.
 

public OperationResult<IEnumerable<INDICATORI>> GetIndicatoriFromDashboardAsync(int idDashboard, Action<IEnumerable<INDICATORI>> onSuccess = null, Action<Exception> onFail = null)

      {

          var query = entityManagerProvider.Manager.INDICATORI

                     .Include(o1 => o1.SNAPSHOT)
                     .Where(x => x.Dashboards.Any(y => y.ID == idDashboard));

 

          var op = query.ExecuteAsync();

 

          return op.OnComplete(onSuccess, onFail).AsOperationResult();

      }


Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 31-May-2012 at 10:36am
Ok, so you want to query INDICATORI entities and not DBOARD entities. So, first of all your query should start with INDICATORI, because that's what you want to return. Based on your relationships, INDICATORI should have a DashboardID property. Not sure what it's called in your model.
 
So, the following should work, assuming the names are correct. A little tip on the side, make a habbit of appending Async at the end of asynchronous methods. Makes it clear to the caller that the method follows an asynchronous calling pattern.
 

public OperationResult<IEnumerable<INDICATORI>> GetIndicatoriFromDashboardAsync(int idDashboard, Action<IEnumerable<INDICATORI>> onSuccess = null, Action<Exception> onFail = null)

      {

          var query = entityManagerProvider.Manager.INDICATORI

                     .Include(o1 => o1.SNAPSHOT)
                     .Where(x => x.DashboardID == idDashboard);

 

          var op = query.ExecuteAsync();

 

          return op.OnComplete(onSuccess, onFail).AsOperationResult();

      }


 
 


Edited by mgood - 31-May-2012 at 10:38am
Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Posted: 31-May-2012 at 8:52am
Hello,
I premit I'm fair new of Ideablade....
I'm tring to fetch data from a silverlight application with mvvm (cocktail),I've this kind of relation

Dashboard (*) <-> (*) Indicatori (1) -> (*) SNAPSHOT

I'm able to run this query and have the Snapshot taken with include

public OperationResult<IEnumerable<INDICATORI>> GetIndicatoriFromDashboard(int idDashboard, Action<IEnumerable> onSuccess = null, Action<Exception> onFail = null)

       {

           var q = entityManagerProvider.Manager.INDICATORI.Select(o1 => o1).Include(o1=>o1.SNAPSHOT);

 

           EntityQueryOperation<INDICATORI> op = q.ExecuteAsync();

 

           return op.OnComplete(onSuccess, onFail).AsOperationResult<INDICATORI>();

       }


I'm not able to filter on idDashboard since if I do

public OperationResult<IEnumerable<RelatedEntityList<INDICATORI>>> GetIndicatoriFromDashboard(int idDashboard, Action<IEnumerable> onSuccess = null, Action<Exception> onFail = null)

      {

          var query = entityManagerProvider.Manager.DBOARD.Where(o1 => o1.ID == idDashboard).Select(o1 => o1.INDICATORI).Include("SNAPSHOT");

          var q = entityManagerProvider.Manager.INDICATORI.Select(o1 => o1).Include(o1 => o1.SNAPSHOT);

 

          var op = query.ExecuteAsync();

 

 

          return op.OnComplete(onSuccess, onFail).AsOperationResult();

      }


Executing this I got The result type of the query is neither an EntityType nor a CollectionType with an entity element type. An Include path can only be specified for a query with one of these result types.

I've read that include cannot be filtered....but how can I filter from idDashboard? if I were in wpf I would have done a ToList and then split but in sl I must do it async......any help?
Thanks

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down