New Posts New Posts RSS Feed: Question about DB relations in entity manager
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Question about DB relations in entity manager

 Post Reply Post Reply
Author
ehsan View Drop Down
Newbie
Newbie
Avatar

Joined: 02-Jun-2010
Posts: 15
Post Options Post Options   Quote ehsan Quote  Post ReplyReply Direct Link To This Post Topic: Question about DB relations in entity manager
    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)


Edited by ehsan - 27-Jun-2010 at 10:43am
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
ehsan View Drop Down
Newbie
Newbie
Avatar

Joined: 02-Jun-2010
Posts: 15
Post Options Post Options   Quote ehsan Quote  Post ReplyReply Direct Link To This Post 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 ?


Edited by ehsan - 01-Jul-2010 at 4:33am
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down