Home  >  Article  >  Backend Development  >  Discuss how to use the EF framework under VS2015

Discuss how to use the EF framework under VS2015

巴扎黑
巴扎黑Original
2017-08-11 11:56:375124browse

This article mainly introduces in detail how to simply use the EF framework under VS2015. It has certain reference value. Interested friends can refer to

How to simply use the EF framework under VS2015. Method, the specific content is as follows

Create a new Model1.edmx file

The page references the database Model1. Create the model file of the AD database as follows,

Find the following menu

Find the required reference database class name.

Quote in the background of the page


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace WebApplication4
{
 public partial class WebForm1 : System.Web.UI.Page
 {
  protected readonly tb_FaceGroup _context;
 
  private readonly ADEntities datesql = new ADEntities();
  protected void Page_Load(object sender, EventArgs e)
  {
   ADEntities db = new ADEntities();//所需要实例化的类
 
   //添加动作
   //tb_user dd = new tb_user();
   //dd.ID = "ddsds";
   //dd.Wid = "dsdssd";
   //db.tb_user.Add(dd);
   //db.SaveChanges();--把以上代码变更到数据库
 
 
 
   //查询
   // List<tb_user> lstOrder = new List<tb_user>();
 
   tb_user lstOrder = new tb_user();
   // lstOrder = datesql.tb_user.GroupBy(r => r.ID == "ddsds");
 
   var info = datesql.tb_user.OrderByDescending(r => r.ID == "ddsds");// .FirstOrDefault(r => r.ID == "ddsds");
 
 
   //打印查询结果 
   if (info.Any())
   {
    foreach (var userEntity in info)
    {
     Console.WriteLine(userEntity.ID + "----" + userEntity.Wid);
    }
   }
 
 
  }
 
  
 }
}

The above is the detailed content of Discuss how to use the EF framework under VS2015. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn