How to Use the explain table in EF to query tokens

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.