0

I am using Telerik open Access, I have three different data models like:

UserEntitiesModel->account_details
ProfileEntitiesModel->biographic_details
ContactsEntitiesModel->contact_groups

I have three different tables in different data models. I want to load the data from all the tables; I used joins and wrote the lambda expression, but it is throwing an exception

InvalidOperationException unhandled by user code

Can you tell me how to retrieve the the data from different tables in different data models?

George Netu
  • 2,758
  • 4
  • 28
  • 49
steve
  • 664
  • 4
  • 16
  • 42

1 Answers1

1

You see, different models (rlinq) files generate different Context objects (the ones deriving from OpenAccessContext), they in turn have different internals used and are completely separate. This means you cannot combine them in a LINQ query.

LINQ queries are per-context and are (usually) executed on the sql server. OpenAccess cannot know how two models correlate and whether they are from the same database instance.

That being said, if the data models are just different parts of the same database (and use the same (or similar) connection string) you should be able to aggregate the models into a single context object. The context objects are initialized with a MetadataSource, and you can merge the models you have into a single one, using the AggregateMetadataSource. You will need to implement your own Context object, and it is more work, but it should work.

If you don't want to go into such trouble, you can always enumerate the results from your tables using .ToList() before using them in the LINQ query. This however means that you will be retrieving more data on the client that you wouldn't need otherwise.

sovanesyan
  • 1,098
  • 1
  • 8
  • 15
  • Thanks for the suggestion.I will implement this and let u know after implement this – steve Jul 16 '12 at 09:10
  • I used ToList for retrieving the data from first two entity models.How can i use this values in the linq query,I think for that also i have to use join.am i right? – steve Jul 16 '12 at 09:59
  • the same query should work just fine, just retrieve all 3 results in local variables using ToList() – sovanesyan Jul 16 '12 at 10:22
  • I retrieved the 3 results in the local variables,after that how can i write the query for the required condition. – steve Jul 16 '12 at 11:04