1. First, we want the list to display the common data of the two tables.
There are two tables
Public class mytype
{
Public int mytypeid {Get; set ;}
Public String mytypename {Get; set ;}
}
Public class author
{
Public int authorid {Get; set ;}
Public String authorname {Get; set ;}
}
2. Create a new file, and then add a class
Public class all
{
Public int ID {Get; set ;}
Public string type {Get; set ;}
Public String other {Get; set ;}
}
3. Public class mytrycontroller: Controller
{
//
// Get:/mytry/
Allcontext DB = new allcontext ();
Public actionresult index () // here we retrieve the number in all.
{
VaR A = from I in db. mytype
From J in db. Author
Where I. mytypeid = J. authorid
Select New all {id = I. mytypeid, type = I. mytypename, other = J. authorname };
Return view ();
}
}
4. Then the corresponding response plane
@ Model ienumerable <mvcapplication12.viewmodel. All>
Then, the data you need will come out.
@ Foreach (VAR item in Model)
{
@ Item. ID
@ Item. Type
@ Item. Other
}
There is still a similar method
First, add an all Class
Namespace mvcapplication12.viewmodel
{
Public class all
{
Public ienumerable <author> author {Get; set ;}
Public ienumerable <mytype> mytype {Get; set ;}
}
}
In the Controller
Public class mytrycontroller: Controller
{
//
// Get:/mytry/
Allcontext DB = new allcontext ();
Viewmodel. All Al = new viewmodel. All ();
Public actionresult index () // here we retrieve the number in all.
{
VaR A = from I in db. mytype
From J in db. Author
Where I. mytypeid = J. authorid
Select New myclass {id = I. mytypeid, type = I. mytypename, name = J. authorname };
Return view ();
}
}
Public class myclass
{
Public int ID {Get; set ;}
Public string type {Get; set ;}
Public string name {Get; set ;}
}
Then, on the Response plane
@ Model ienumerable <mvcapplication12.controllers. myclass>
@ Foreach (VAR item in Model)
{
@ Item. ID
@ Item. Name
@ Item. Type
}
This is also possible.
OK
How to Use the explain table in EF to query tokens