RE: Decoupling from RIA services

2010-09-03 Thread Steven Nagy
Hi David,

We are using RIA and a standard ViewModel takes an IRepositoryT where T : 
Entity.
When I want to track lists of items I use ObservableCollectionT as well and 
add it to the EntitySet if I want it commited to the database.
Under the hood, an IRepositoryProduct and IRepositoryCategory will use the 
same domain context however we are in the process of adjusting this to use the 
same domain context only per ViewModel (ie unit of work) and this is managed by 
the IOC container.

However I never really need to create NEW entity sets and was unsure how to 
answer your question. Usually with .Include(Products) you would get all the 
products with a category, or at least an empty entity set if there are none, 
and you can still add to that existing entity set on the Category entity.

Steven Nagy
Readify | Senior Consultant
M: +61 404 044 513 | E: steven.n...@readify.netsip:steven.n...@readify.net | 
B: azure.snagy.namehttp://azure.snagy.name/

From: ozsilverlight-boun...@ozsilverlight.com 
[mailto:ozsilverlight-boun...@ozsilverlight.com] On Behalf Of David Burela
Sent: Thursday, 2 September 2010 4:45 PM
To: ozSilverlight
Subject: Re: Decoupling from RIA services

Answer: Just hack it out and use an ObservableCollection instead.

On 2 September 2010 14:10, David Burela 
david.bur...@gmail.commailto:david.bur...@gmail.com wrote:
I am working on a new Silverlight application.
It is a standard MVVM application using RIA services to retrieve the data.

I am trying to not have the domain service in my ViewModel, and I have managed 
to get 99% of the domain context out.
The only thing that I am just left with, is a EntitySet as the base of one of 
my collections, which I'm not too worried about. But for testing, etc. I need 
to be able to new up one of these.

When i go
var entityset = new EnitySetProducts();
It does create a new EntitySet. However, it doesn't initialise it's internal 
list. So when I try to add items to it in my tests the whole thing throws null 
reference exceptions. Does anyone have a way of creating EntitySets client side 
so I can have everything decoupled from my domain context?

-David Burela

___
ozsilverlight mailing list
ozsilverlight@ozsilverlight.com
http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight


Re: Decoupling from RIA services

2010-09-03 Thread David Burela
I am using ViewModels that use IRepositoryTEntity. I had methods on the
IRepository that would return EntitySetTEntity.
The problem with them, was that I was not able to create EntitySets for a
unit test...

I solved that problem by just having the repository process the results and
return back a List or ObservableCollection.
I was only using EntitySets because of a control I was using, so I just
ripped apart their source code and replaced the underlying EntitySet
collection with an ObservableCollection.

Up until that point I had everything working well and decoupled.
The entire ViewModel just had ObservableCollections and IRepositoryTEntity
and was completely unit testable.
View - ViewModel - IRepository - Ria DataContext

The next problem came when I tried to apply paging on top of this.

I created a new PagingCollectionTEntity to hold this. It implements the
IPagableCollectionView interface, which all paging grids use (builtin
silverlight, Telerik, etc.). The grid would make the calls to the interface
that it was paging, and the PagingCollectionTEntity would automatically
pass on the correct parameters to the repository.

The problem I had then was how can you apply arbitrary filtering to your
grid through a repository. You can filter a grid by any column and you need
those to go through. Creating 50 methods/parameters on a repository isn't
feasible. So I tried to get my grid/PagingCollection to work on the
IQueryable.
*The problem being you can not assign an IQueryable object to the
datacontext*

You can create your own IQueryable with
Enumerable.EmptyTEntity.AsQueryable().  Usually you could just union that
with a query you already have going. If you could do that, you could pass
your IQueryable down to the datacontext and everything would be fine.
However you can only GET the IQueryable from a datacontext, you can not SET
it. And they have not exposed the .Union() method on the datacontext query.
If they did expose either a union or a way to set the IQueryable, then it
would be possible to have a completely decoupled viewmodel that allowed you
to do arbitrary paging  filtering :-(

-David Burela



On 3 September 2010 16:18, Steven Nagy steven.n...@readify.net wrote:

 Hi David,



 We are using RIA and a standard ViewModel takes an IRepositoryT where T :
 Entity.

 When I want to track lists of items I use ObservableCollectionT as well
 and add it to the EntitySet if I want it commited to the database.

 Under the hood, an IRepositoryProduct and IRepositoryCategory will use
 the same domain context however we are in the process of adjusting this to
 use the same domain context only per ViewModel (ie unit of work) and this is
 managed by the IOC container.



 However I never really need to create NEW entity sets and was unsure how to
 answer your question. Usually with .Include(“Products”) you would get all
 the products with a category, or at least an empty entity set if there are
 none, and you can still add to that existing entity set on the Category
 entity.



 *Steven Nagy
 *Readify | Senior Consultant

 M: +61 404 044 513 | E: steven.n...@readify.net | B: azure.snagy.name



 *From:* ozsilverlight-boun...@ozsilverlight.com [mailto:
 ozsilverlight-boun...@ozsilverlight.com] *On Behalf Of *David Burela
 *Sent:* Thursday, 2 September 2010 4:45 PM
 *To:* ozSilverlight
 *Subject:* Re: Decoupling from RIA services



 Answer: Just hack it out and use an ObservableCollection instead.



 On 2 September 2010 14:10, David Burela david.bur...@gmail.com wrote:

 I am working on a new Silverlight application.

 It is a standard MVVM application using RIA services to retrieve the data.



 I am trying to not have the domain service in my ViewModel, and I have
 managed to get 99% of the domain context out.

 The only thing that I am just left with, is a EntitySet as the base of
 one of my collections, which I'm not too worried about. But for testing,
 etc. I need to be able to new up one of these.



 When i go

 var entityset = new EnitySetProducts();

 It does create a new EntitySet. However, it doesn't initialise it's
 internal list. So when I try to add items to it in my tests the whole thing
 throws null reference exceptions. Does anyone have a way of creating
 EntitySets client side so I can have everything decoupled from my domain
 context?



 -David Burela



 ___
 ozsilverlight mailing list
 ozsilverlight@ozsilverlight.com
 http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight


___
ozsilverlight mailing list
ozsilverlight@ozsilverlight.com
http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight