Linq to Entity - is it possible to navigate to another table in the model when in the MVC list template

in a project template solution (dynamic data web application), I have a model and it is all good. - Get a list of tables, select edit, etc.

But my database is linking tables that only contain proxy keys, so the list template just displays the fk value

diagram of the table

Is there a way to concatenate a list of rows in a primary table with a check of another table based on fk?

More akin to a join in SQL? but using Linq2Entity and MetaModel?

Below is the List.aspx.cs - seems to bind the standard grid to the entitydatasource, but this is relative to the current table as per route in MVC.

But as you can see, I need to go and query the Person, Role and Link table through the model to get the other fields for this to be useful. vstudio

PS want to try and store this in LINQ2Entity if possible - try grok

The natural thing I want to do is start dropping new sql queries to go and fetch values. But that's not the idiom.

0


source to share


2 answers


you can reference the metamodel via dataContext

MetaModel refMetaModel = MetaModel.GetModel(typeof(yourdataContextName));
MetaTable refMetaModel;
refMetaModel =  refMetaModel.GetTable("yourTableName");

      



PS looked at your code and this works in your sceanrio. You can get tables from the model and then check the data returned for each table in the model

MSDN article on MetaModel

+1


source


Uses this also from Linq to Entities model -

Using dataContext - you can get the most important data acutal.



MetaModel allows access to dataModel which gives you ddl type information

//use the datacontext to get the underlying data
      using (brrdbEntities brr = new brr_dbEntities())
      {
          ObjectQuery<person> people = brr.person;
          IQueryable<string> names = from p in people select p.person_name;
          foreach (var name    in names)

      

0


source







All Articles