Print Page | Close Window

Help with Entities

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2426
Printed Date: 06-Sep-2025 at 3:43pm


Topic: Help with Entities
Posted By: rgillingham
Subject: Help with Entities
Date Posted: 07-Jan-2011 at 6:42am
Hi

We're evaluating how we can use/benefit from DevForce with PostgreSQL - and we have dot connect for Postgres from DevArt

We have a lot of stored procedures in our database and if we try to import these EF complains that they are composable and cannot be imported.  Ok - shame.

So we thought why not use use ADO.net to get the stored procedure resultset and then manuall marshal this into DevForce entities.

If we create a blank mode and add a DevForce entity into it with some properties then we should be able to do something like this on the server

        [Query]
        public IEnumerable<LocationEntity> FetchLocations()
        {
            List<LocationEntity> locations = new List<LocationEntity>();
            var location = new LocationEntity();
            location.location_short_id = "123";

            locations.Add(location);

            IEnumerable<LocationEntity> result = locations;
            return result;
        }

and call it with this from the Silverlight client

extend the domain model

        public static EntityQuery<LocationEntity> Locations(this EntityManager em)
        {
            return new EntityQuery<LocationEntity>("FetchLocations", em);
        }

then call in with

        public void GetLocations()
        {
            var eq = EntityManager.DefaultManager.Locations();

            eq.ExecuteAsync((r) => OnLocations(r) );
        }

If I do this though I get an unhandled exception in the silverlight client of

"...No mapping specified for instances of the EntitySet and AssociationSet in the EntityContainer"

So I guess where I'm coming from is - how can we use the EntityFramework model to define entity shapes but then manually move them around between the tiers.  I know we can use the POCO pattern but this then becomes a mission for adding in verifiers etc.

Another approach I tried was

        [AllowRpc]
        public static Object GetLocations(IPrincipal pPrincipal, EntityManager pPm, params Object[] pArgs)
        {
            List<LocationEntity> locations = new List<LocationEntity>();
            var location = pPm.CreateEntity<LocationEntity>();
            location.location_short_id = "123";

            locations.Add(location);

            IEnumerable<LocationEntity> result = locations;
            return result;
        }

But this complained that the result was not serializable.

Any help and guidance welcomed.

Richard






Replies:
Posted By: kimj
Date Posted: 10-Jan-2011 at 3:20pm
The first approach doesn't work since it's a mix of POCO and EF.  Because the entities were defined in the EDM DevForce is treating them as EF entities and not taking the POCO processing path which would call your FetchLocations query method.  You can work around this by creating a custom EntityServerQueryInterceptor, but it may not be a very robust solution.  The interceptor would need to override the standard ExecuteQuery logic to explicitly call your fetch method, and then force the result.  Something like this: 

  public class QueryInterceptor : EntityServerQueryInterceptor {

    protected override bool ExecuteQuery() {
      PocoServiceProvider provider = new PocoServiceProvider();
      var list = provider.FetchLocations();
      ForceResult(list);
      return true;
    }
  }

If you support create/update/delete then you'd also need a custom EntityServerSaveInterceptor to override default save logic.
 
Your second approach, using the RPC method, should work as long as the entities are also defined on the Silverlight client, which they will be if  the *Ib.Designer.cs file is added as a link. 



Print Page | Close Window