Observable EntitySets/NavigationCollections in BreezeJS

65 Views Asked by At

We are considesing using BreezeJS as analogous solution to our current WCF Ria Services + Silverlight pair. In WCF Ria Services we have client DataContext containing EntitySet instances which get populated with queries. For example, there we might have three methods on our DomainService described below. Assume also that User is linked to Order as 1-to-many:

public IEnumerable<User> GetFirst10Users(){
   //retrieve from DB with EF
   return ObjectContext.Users.OrderBy(u => u.Id).Take(10);
}

public IEnumerable<User> GetLast10Users(){
   //retrieve from DB with EF
   return ObjectContext.Users.OrderByDesc(u => u.Id).Take(10);
}

public IEnumerable<Order> GetOrders(){
   //retrieve from DB with EF
   return ObjectContext.Orders;
}

As a result we'll have something like this generated for us on client-side:

public class Context{
    public EntitySet<User> Users {...};
    public EntitySet<Order> Orders {...};

    public EntityQuery<User> GetFirst10UsersQuery(){
    }

    public EntityQuery<User> GetLast10UsersQuery(){
    }

    public EntityQuery<Orders> GetOrdersQuery(){
    }
}

If we execute first two queries, we'll end up having union of their results in Users collection. Executing the third one will give us all orders in Orders collection, but only subset of those will be contained in Navigation collections of User instances on client. It works really well and as Entities get added to Users collection(by query, or by user's action, or by other viewmodel's side effect) those get displayed on UI right away through binding to ObservableCollection wrapper over Users EntitySet. The same gets reflected on canceling changes, and I don't need to do a lot for that - just providing observable interface.

With BreezeJS and JS particularly, it looks like that I should be subscribing to various events of Breeze and synchronize data with my Kendo UI observable array instance (which is in fact copying data between breeze cache and Kendo UI observable array).

In WCF Ria Services, Context.Users entityset has EntityAdded / EntityDeleted events which makes it possible to handle additions/removals in our ViewModels.

The same events are also available for NavigationCollections, so we might do user.Orders.EntityAdded += ... for example.

So, I'm trying to implement something similar to what we had in WCF Ria Services + Silverlight using Angular + BreezeJS + Kendo UI in TypeScript. I have kind of found analogs for EntityAdded/Deleted events for EntitySet in Breeze but didn't find anything like this for NavigationCollections.

Could someone let me know if the path I'm trying to go with is completely awkward in BreezeJS/KendoUI/Angular world? If no, how do I handle changes in navigation collections in BreezeJS?

0

There are 0 best solutions below