.net Core - SqlSugar use

A, DbContext configuration

    public  class the DbContext 
    { 
        public the DbContext () 
        { 
            Db = new new SqlSugarClient ( new new ConnectionConfig () 
            { 
                the ConnectionString = " Server = 120.79.21.96; UID = the Test; the Test pwd =; = the Test Database " , 
                the DbType = DbType.MySql, 
                InitKeyType = InitKeyType .Attribute, // read from the characteristics of the primary key and additional information from 
                IsAutoCloseConnection = to true , // enable auto release mode and EF same principle I will not explain 
            });
            @ -Tone code is used to print the SQL 
            Db.Aop.OnLogExecuting = (SQL, Pars) => 
            { 
                Console.WriteLine (SQL + " \ R & lt \ n- " + 
                    Db.Utilities.SerializeObject (pars.ToDictionary (IT => IT. the ParameterName, IT => it.Value))); 
                Console.WriteLine (); 
            }; 
        } 
        // Note: not written static and can not be written static 
        public SqlSugarClient Db; // for processing transactions and complex multi-table queries operation 
    }

Second, the use

        public IActionResult GetInit()
        {
            DbContext db = new DbContext();

            List<DbList> a =db.Db.SqlQueryable<DbList>("SELECT a.SubG_ID,a.SubG_GroupName, d.User_Id, d.User_Name, d.User_Avatar FROM SubGroup AS a LEFT JOIN User_SubGroup AS b ON a.SubG_ID = b.SubG_ById INNER JOIN Friend AS c ON b.User_Id = c.Frie_ById INNER JOIN Users AS d ON d.User_Id = c.Frie_ById WHERE c.User_Id = 5  ").ToList();

            string str = "{\ "Code \": 0, \ "msg \": \ "\", \ "data \": {\ "mine \": {\ "username \": \ "paper plane \", \ "id \ ": \" 100000 \ ", \" status \ ": \" online \ ", \" sign \ ": \" in deep coding world, doing a lightweight paper airplane \ ", \" avatar \ " : \ "http: //cdn.firstlinkapp.com/upload/2016_6/1465575923433_33812.jpg \"}, \ "friend \": [{\ "groupname \": \ "distal Cock code \", \ "id \ ": 1, \" online \ ": 2, \" list \ ": [{\" username \ ": \" Yin heart \ ", \" id \ ": \" 100001 \ ", \" avatar \ " : \ "http: //tp1.sinaimg.cn/1571889140/180/40030060651/1 \", \ "sign \": \ "these are all the test data, the actual return to strictly follow the format \"}, { \ "username \": \ "Z_ CHING \", \ "id \": \ "108101 \", \ "avatar \": \ "http://tva3.sinaimg.cn/crop.0.0.512.512.180/8693225ajw8f2rt20ptykj20e80e8weu.jpg \ ", \" sign \ ": \" micro electricity supplier Daren \ "}, {\" username \ ": \" Lemon_CC \ ", \" id \ ": \" 102101 \ ", \" avatar \ ": \" http: //tp2.sinaimg.cn/1833062053/180/5643591594/0 \ ", \" sign \ ": \" \ "}, {\" username \ ": \ "Ma Xiaoyun \", \ "id \": \ "168168 \", \ "avatar \": \ "http: //tp4.sinaimg.cn/2145291155/180/5601307179/1 \", \ "sign \" : \ "to make the code \ world is not difficult to write"}, {\ "username \": \ "Xuxiao Zheng \", \ "id \": \ "666666 \", \ "avatar \": \ "http: / /tp2.sinaimg.cn/1783286485/180/5677568891/1 \ ", \" sign \ ": \" Code in the embarrassing way, in the end have to write \ "}]}, {\" groupname \ ": \" network red \ ", \" id \ ": 2, \" online \ ": 3, \" list \ ": [{\" username \ ":\ "Luo Yufeng \", \ "id \": \ "121286 \", \ "avatar \": \ "http: //tp1.sinaimg.cn/1241679004/180/5743814375/0 \", \ "sign \ ": \" bad in their own strength, do not to believe what the media and reporters that they are not good people, and sometimes they interview candidates for the party is to trap \ "}, {\" username \. ": \" Nagasawa Azusa Azusa \ ", \" id \ ": \" 100001222 \ ", \" sign \ ": \" I am a Japanese female artist Nagasawa thou zu Connecticut \ ", \" avatar \ ": \" http: // tva1.sinaimg.cn/crop.0.0.180.180.180/86b15b6cjw1e8qgp5bmzyj2050050aa8.jpg \ "}, {\" username \ ": \" fish _MsYuyu \ ", \" id \ ": \" 12123454 \ ", \ "avatar \": \ "http: //tp1.sinaimg.cn/5286730964/50/5745125631/0 \", \ "sign \":! \ "I was mad that it is too low quasi super punchline \ "}, {\" username \ ": \" Xie Nan \ ", \" id \ ": \" 10034001 \ ", \" avatar \ ": \" http: //tp4.sinaimg.cn/1665074831/180/5617130952/0\",\"sign\":\"\"},{\"username\":\"柏雪近在它香\",\"id\":\"3435343\",\"avatar\":\"http://tp2.sinaimg.cn/2518326245/180/5636099025/0\",\"sign\":\"\"}]},{\"groupname\":\"我心中的女神\",\"id\":3,\"online\":1,\"list\":[{\"username\":\"林心如\",\"id\":\"76543\",\"avatar\":\"http://tp3.sinaimg.cn/1223762662/180/5741707953/0\",\"sign\":\"我爱贤心\"},{\"username\":\"佟丽娅\",\"id\":\"4803920\",\"avatar\":\"http://tp4.sinaimg.cn/1345566427/180/5730976522/0\",\"sign\":\"我也爱贤心吖吖啊\"}]}],\"group\":[{\"groupname\":\"前端群\",\"id\":\"101\",\"avatar\":\"http://tp2.sinaimg.cn/2211874245/180/40050524279/0\"},{\"groupname\":\"Fly社区官方群\",\"id\":\"102\",\"avatar\":\"http://tp2.sinaimg.cn/5488749285/50/5719808192/1\"}]}}";
            var result = JsonConvert.DeserializeObject(str);
            //List<string> dic = ChatHub.GetOnlineUserIds();

            return Json(result);
        }

 

Guess you like

Origin www.cnblogs.com/fger/p/11612099.html