New Posts New Posts RSS Feed: Does Devforce EF be able to create joint table object?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Does Devforce EF be able to create joint table object?

 Post Reply Post Reply
Author
monkeyking View Drop Down
Groupie
Groupie
Avatar

Joined: 04-Mar-2009
Location: brisbane
Posts: 68
Post Options Post Options   Quote monkeyking Quote  Post ReplyReply Direct Link To This Post Topic: Does Devforce EF be able to create joint table object?
    Posted: 07-May-2009 at 9:00pm
devforce can generate a list of entities which has the same structure as DB tables. but i want some specific data from serveral different tables, does devforce EF be able to provide a function that can create an new entity which joint each different tables' information?

for instance, i want an object which contains the properties of Account_no, Customer_name, but these two columns are in different data tables of DB, am i be able to create such object by using deforce EF? if yes, how can i do that, and which chapter i should look at?
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 08-May-2009 at 10:16am
DevForce WinClient uses two models: 1) a "domain" model built from and layered over 2) the Entity Framework entity model.   It's the EF entity model, with both its features and limitations, which interfaces directly with the database.  The domain model does not currently support any kind of extensive modification to the EF model, so if EF doesn't support something then it's also likely not supported by DevForce EF.  In this case, EF would require you to use a view to achieve what you need.
 
If you don't need to define an Entity, but just wish to retrieve joined data like this at run time, you can use an anonymous type query.
Back to Top
monkeyking View Drop Down
Groupie
Groupie
Avatar

Joined: 04-Mar-2009
Location: brisbane
Posts: 68
Post Options Post Options   Quote monkeyking Quote  Post ReplyReply Direct Link To This Post Posted: 09-May-2009 at 12:17am
what do you mean by "EF would require you to use a view to achieve what you need."

thx kimj, you always anwer my question. are you a company member of ideablade?
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 09-May-2009 at 9:38am

I meant that the Entity Framework will not let you "pick and choose" columns from several tables to define a single Entity, and that a database view (or defining query) is required.  I guess I should add that a stored procedure would do the job too.   What you want is more of an advanced topic, and we don't have anything covering this in our documentation or samples.   Here's some information from Microsoft on advanced data models:  http://msdn.microsoft.com/en-us/library/bb738640.aspx

Yes, I am an IdeaBlade employee.
Back to Top
monkeyking View Drop Down
Groupie
Groupie
Avatar

Joined: 04-Mar-2009
Location: brisbane
Posts: 68
Post Options Post Options   Quote monkeyking Quote  Post ReplyReply Direct Link To This Post Posted: 21-May-2009 at 7:17pm
thx Kimj,

last thing, can you please tell me how to retrieve more than 2 tables' info into 1 anonymous type variable please? I have read the tutorial, but there is no example in this feature.

Regards
 
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 22-May-2009 at 9:29am
Here's an example query returning an anonymous type joining an OrderSummary, Customer, Employee and OrderDetails.
 
      var q0 = entityManager.OrderSummaries
                    .Where(o=> o.ShipCity == "Madrid")
                    .Select(o => new { OrderId = o.Id, Customer = o.Customer.CompanyName,
                               Employee = o.Employee.LastName, o.OrderDetails });
 
Sorry we don't have any samples in our tutorials yet, but they should work the same in DevForce as in LINQ or EF.  Here's a good post by Scott Guthrie explaining anonymous types - http://weblogs.asp.net/scottgu/archive/2007/05/15/new-orcas-language-feature-anonymous-types.aspx.
Back to Top
monkeyking View Drop Down
Groupie
Groupie
Avatar

Joined: 04-Mar-2009
Location: brisbane
Posts: 68
Post Options Post Options   Quote monkeyking Quote  Post ReplyReply Direct Link To This Post Posted: 24-May-2009 at 5:34pm
Thx kimj,

I notice that all information is retreived from OrderSummary, although the query contains different table's info, but all other table must connect with OrderSummary by the FKs, don't they? Therefore, if there is no FKs, even Anonymous type can't retrieve data from different tables, does it?
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 25-May-2009 at 5:06pm
You can retrieve data from a cross join of unrelated data and project into an anonymous type.    Something like this (although this particular query is pretty silly) can be done:
 
 var query = from p in entityManager.Products
                    from a in entityManager.Areas
                    select new { p.ProductName, a.Description };
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down