Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说
sqlsugar使用教程_sql数据库怎么用,希望能够帮助你!!!。
sqlsugar是一款非常轻量级并且特别强大的ORM,支持常见的关系型数据库(Oracle , sqlserver , MySQL等等等等),本文示例的是SqlServer,更多一起玩耍的朋友可以关注鄙人的公众号,获取更多源码哦
思路和流程如下
using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebApplication1.Helper {
public class dbContext {
private static SqlSugarClient _db = null; /// <summary> /// test是数据库名 /// </summary> public static string ConnectionString = "Data Source=localhost;Initial Catalog=test;User id=sa;Password="; public static SqlSugarClient CretClient() {
_db = new SqlSugarClient(new ConnectionConfig() {
ConnectionString = ConnectionString, //数据库连接字符串 DbType = DbType.SqlServer, //必填 IsAutoCloseConnection = false, //默认false InitKeyType = InitKeyType.Attribute }); return _db; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebApplication1.Helper {
public partial class test {
public int ID {
get; set; } public string usernage {
get; set; } public string password {
get; set; } } }
using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using WebApplication1.Helper; namespace WebApplication1.Controllers {
public class HomeController : Controller {
public static SqlSugarClient DbContext = dbContext.CretClient(); public ActionResult Index() {
var results = DbContext.GetSimpleClient<test>().GetList().Where(i => i.ID == 1); var sqlResults = DbContext.SqlQueryable<test>("select * from test where ID = 1").ToList(); return View(); } public ActionResult About() {
ViewBag.Message = "Your application description page."; return View(); } public ActionResult Contact() {
ViewBag.Message = "Your contact page."; return View(); } } }
今天的分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。
上一篇
已是最后文章
下一篇
已是最新文章