Print Page | Close Window

Question about DB relations in entity manager

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=1920
Printed Date: 12-Jan-2026 at 2:30pm


Topic: Question about DB relations in entity manager
Posted By: ehsan
Subject: Question about DB relations in entity manager
Date Posted: 27-Jun-2010 at 10:41am
I've 3 simple sql tables :

t1( id int primary key, name char(16) );

t2( id int primary key, name char(16) );

t3( id1 int references t1(id), id2 int references t2(id) );

as you see, t3 is a N-to-N relation between t1 & t2. I added this tables to my data model & using entity manager I can query t1 & t2.
 
If I want to access related records between t1 & t2, I use something like this (here I get all records from t2 which are in relation with t1 using a record with id=X) :
 
RelatedEntityList<t2> list = from r in mgr.t1s where r.id==X select r.t2s ;
 
but this linq query returns ALL related records.
I want to know is there any way to get only a subset of this list from the server (instead of retrieving all of them) ?
I need it because a record in t1 table may be in a relation with MANY! records of t2 & vice versa (for instance, suppose a 1 to 1000 relation)



Replies:
Posted By: GregD
Date Posted: 30-Jun-2010 at 1:54pm
You can get an instance t1Instance of t1 with id=X, then just reference

    t1Instance.t2s

or you can do it in one pass using

    mgr.t1s.Where(r=>r.id == X).Include("t2s")

Of course all data retrievals are asynchronous in Silverlight.

I can't get a statement of the form you used:

   RelatedEntityList<t2> list = from r in mgr.t1s where r.id==X select r.t2s ;

even to compile, so I'm wondering how you determined what it returns.


Posted By: ehsan
Date Posted: 01-Jul-2010 at 4:32am

Yes, thats wonderful, But I'm currently use that in silverlight !

& also I can call server methods synchronously & I don't know why !
 
for example I've this partial class :
 

public partial class TestEntities  {

public int add(int a, int b)

{

   return a + b;

}

}
 
Although I didn't mark add method with [AllowRpc] & that's not static, but i can call it directly & synchronously from silverlight client !!! (I just added a link from server side partial class to my silverlight client) & then :

TestEntities.DefaultManager.add(1, 2);//It executes successfully & synchronously & returns the correct result !

 At first I thought that's a devforce feature, but it's also said in devforce documents that all silverlight calls must be async !
 
what do you think ?


Posted By: GregD
Date Posted: 01-Jul-2010 at 4:26pm
You can make synchronous queries, but they just use whatever's in the local cache. That turns out to be a nice feature, though, since in some situations you can just pre-load all the data your user needs to work with and do everything synchronously.

As for your TestEntities class, if you linked it into your Silverlight project then it's compiled into that assembly and is just like any other local class.



Print Page | Close Window