1.

How Do You Query In Entity Model When The Result Has A Join From From Different Database Other Than The Entity Model?

Answer»

E.g.: SELECT t1.c1, t2.c2 FROM table1 AS t1 JOIN table2 t2 ON t1.c1 = t2.c1
As the entity model doesn’t SUPPORT QUERYING from any entity other than the entities defined in Entity Data Model, we have to query aginst the data base using ExecuteStoredQuery of the context.

Following CODE snippet shows how to query when other databases are joined.

Code:

string query = "SELECT t1.c1, t2.c2 FROM table1 AS t1 JOIN table2 t2 ON t1.c1 = t2.c1";

using (var context = new SampleEntities())

{

ObjectResult RECORDS = context.ExecuteStoreQuery(query);

foreach (DbDataRecord record in records)

{

//Do whatever you WANT

}

}

E.g.: SELECT t1.c1, t2.c2 FROM table1 AS t1 JOIN table2 t2 ON t1.c1 = t2.c1
As the entity model doesn’t support querying from any entity other than the entities defined in Entity Data Model, we have to query aginst the data base using ExecuteStoredQuery of the context.

Following code snippet shows how to query when other databases are joined.

Code:

string query = "SELECT t1.c1, t2.c2 FROM table1 AS t1 JOIN table2 t2 ON t1.c1 = t2.c1";

using (var context = new SampleEntities())

{

ObjectResult records = context.ExecuteStoreQuery(query);

foreach (DbDataRecord record in records)

{

//Do whatever you want

}

}



Discussion

No Comment Found