mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-19 22:49:35 +08:00
140 lines
12 KiB
C#
140 lines
12 KiB
C#
![]() |
using Google.Protobuf.WellKnownTypes;
|
|||
|
using MySqlX.XDevAPI.Relational;
|
|||
|
using OrmTest;
|
|||
|
using SqlSugar;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Configuration;
|
|||
|
using System.Linq;
|
|||
|
using System.Net.NetworkInformation;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Xml.Linq;
|
|||
|
|
|||
|
namespace OrmTest
|
|||
|
{
|
|||
|
public class examination
|
|||
|
{
|
|||
|
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
|||
|
public int id { get; set; }
|
|||
|
public int qtype { get; set; }
|
|||
|
public string question { get; set; }
|
|||
|
[SugarColumn(IsJson = true)]
|
|||
|
public List<string> options { get; set; }
|
|||
|
public string answer { get; set; }
|
|||
|
}
|
|||
|
|
|||
|
public class examination_info
|
|||
|
{
|
|||
|
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
|||
|
public int id { get; set; }
|
|||
|
public int exam_id { get; set; }
|
|||
|
public int userid { get; set; }
|
|||
|
public string myanswer;
|
|||
|
public int score { get; set; } = -1;
|
|||
|
public DateTime? submit_time;
|
|||
|
|
|||
|
|
|||
|
[SugarColumn(IsJson = true)]
|
|||
|
public examination exam { get; set; }
|
|||
|
}
|
|||
|
|
|||
|
internal class UnitDtoJsonafda
|
|||
|
{
|
|||
|
public static void Init()
|
|||
|
{
|
|||
|
// ----------------------sql------------------
|
|||
|
// CREATE DATABASE `cochlea` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */;
|
|||
|
// --cochlea.examination definition
|
|||
|
|
|||
|
//CREATE TABLE `examination` (
|
|||
|
// `id` int(11) NOT NULL AUTO_INCREMENT,
|
|||
|
// `qtype` int(11) NOT NULL,
|
|||
|
// `question` varchar(100) NOT NULL,
|
|||
|
// `options` varchar(200) DEFAULT NULL,
|
|||
|
// `answer` varchar(5) NOT NULL,
|
|||
|
// PRIMARY KEY(`id`)
|
|||
|
//) ENGINE = InnoDB AUTO_INCREMENT = 21 DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '试卷';
|
|||
|
|
|||
|
|
|||
|
// --cochlea.examination_info definition
|
|||
|
|
|||
|
//CREATE TABLE `examination_info` (
|
|||
|
// `id` int(11) NOT NULL,
|
|||
|
// `exam_id` int(11) DEFAULT NULL,
|
|||
|
// `userid` int(11) DEFAULT NULL,
|
|||
|
// `myanswer` varchar(100) DEFAULT NULL,
|
|||
|
// `score` int(11) DEFAULT NULL,
|
|||
|
// `submit_time` datetime DEFAULT NULL,
|
|||
|
// PRIMARY KEY(`id`),
|
|||
|
// KEY `examination_info_userid_IDX` (`userid`) USING BTREE
|
|||
|
//) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
//ConfigurationManager.ConnectionStrings["dbconnstr"].ConnectionString;
|
|||
|
SqlSugarClient Db = NewUnitTest.Db;
|
|||
|
|
|||
|
|
|||
|
Db.Ado.ExecuteCommand("-- MySQL dump 10.13 Distrib 8.0.19, for Win64 (x86_64)\r\n--\r\n-- Host: localhost Database: cochlea\r\n-- ------------------------------------------------------\r\n-- Server version\t11.3.2-MariaDB\r\n\r\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\r\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\r\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\r\n/*!50503 SET NAMES utf8mb4 */;\r\n/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\r\n/*!40103 SET TIME_ZONE='+00:00' */;\r\n/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\r\n/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\r\n/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\r\n/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\r\n\r\n--\r\n-- Table structure for table `examination`\r\n--\r\n\r\nDROP TABLE IF EXISTS `examination`;\r\n/*!40101 SET @saved_cs_client = @@character_set_client */;\r\n/*!50503 SET character_set_client = utf8mb4 */;\r\nCREATE TABLE `examination` (\r\n `id` int(11) NOT NULL AUTO_INCREMENT,\r\n `qtype` int(11) NOT NULL,\r\n `question` varchar(100) NOT NULL,\r\n `options` varchar(200) DEFAULT NULL,\r\n `answer` varchar(5) NOT NULL,\r\n PRIMARY KEY (`id`)\r\n) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='试卷';\r\n/*!40101 SET character_set_client = @saved_cs_client */;\r\n\r\n--\r\n-- Dumping data for table `examination`\r\n--\r\n\r\nLOCK TABLES `examination` WRITE;\r\n/*!40000 ALTER TABLE `examination` DISABLE KEYS */;\r\nINSERT INTO `examination` VALUES (1,1,'内耳的听觉感受器是','[\\\"球囊斑\\\",\\\"椭圆囊斑\\\",\\\"壶腹峭\\\",\\\"螺旋器\\\",\\\"前庭阶\\\"]','d'),(2,1,'不属于骨迷路的结构是','[\\\"蜗管\\\",\\\"前庭\\\",\\\"外骨半规管耳蜗\\\",\\\"前骨半规管\\\",\\\"耳蜗\\\"]','a'),(3,1,'前庭蜗器按部位可分为','[\\\"外耳、鼓室和迷路\\\",\\\"耳廓、鼓室和内耳\\\",\\\"外耳、鼓室和耳蜗\\\",\\\"外耳、中耳和内耳\\\",\\\"耳廓、中耳和耳蜗\\\"]','d'),(4,1,'外耳门位于','[\\\"颧骨\\\",\\\"颞骨\\\",\\\"枕骨\\\",\\\"下颌骨\\\",\\\"筛骨\\\"]','b'),(5,1,'鼓室与颅中窝相邻的壁是','[\\\"颈静脉壁\\\",\\\"鼓室盖\\\",\\\"颈动脉壁\\\",\\\"迷路壁\\\",\\\"乳突壁\\\"]','b'),(6,1,'鼓室','[\\\"前壁有面神经管凸\\\",\\\"前庭窗后上方隆起为岬\\\",\\\"后壁有前庭窗、蜗窗\\\",\\\"内侧壁有鼓窦开口\\\",\\\"前壁有咽鼓管开口\\\"]','e'),(7,1,'何者位于中耳内','[\\\"外耳道\\\",\\\"骨半规管\\\",\\\"耳蜗\\\",\\\"听小骨\\\",\\\"鼓膜\\\"]','d'),(8,1,'中耳的组成不包括','[\\\"鼓室\\\",\\\"咽鼓管\\\",\\\"乳突窦\\\",\\\"乳突小房\\\",\\\"前庭\\\"]','e'),(9,1,'鼓室','[\\\"上壁为鼓室盖,邻颅后窝\\\",\\\"前壁上方有咽鼓管通鼻咽部\\\",\\\"下壁为颈动脉壁\\\",\\\"后壁邻颈内静脉始部\\\",\\\"内有两块听小骨肌\\\"]','b'),(10,1,'关于蜗管的描述错误的是','[\\\"位于耳蜗内\\\",\\\"内含内淋巴\\\",\\\"借连合管与球囊相连\\\",\\\"螺旋器位于蜗管的前庭壁(前庭膜上)\\\",\\\"螺旋器位于蜗管的基底膜上\\\"]','d'),(11,1,'与鼓室相通的管道是','[\\\"外耳道\\\",\\\"内耳道\\\",\\\"咽鼓管\\\",\\\"蜗管\\\",\\\"内淋巴管\\\"]','c'),(12,1,'下列有关中耳的描述中,正确的选项是:','[\\\"中耳即鼓室\\\",\\\"中耳全部位于颞骨岩部内\\\",\\\"中耳向内借第二鼓膜与内耳中鼓阶相隔\\\",\\\"中耳向前借咽鼓管通向口咽部\\\",\\\"中耳内粘膜与乳突窦和乳突小房内的粘膜不相连续\\\"]','c'),(13,1,'在鼓室内侧壁可以看到以下结构','[\\\"外半规管凸和鼓膜张肌半管\\\",\\\"面神经管凸和岬\\\",\\\"鼓膜张肌半管和锥隆起\\\",\\\"前庭窗和蜗顶\\\",\\\"蜗窗和蜗顶\\\"]\\r\\n','b'),(14,1,'听骨链由外向内依次是','[\\\"锤骨、砧骨、镫骨\\
|
|||
|
|
|||
|
//
|
|||
|
var exam_info_list = Db.Queryable<examination>()
|
|||
|
.LeftJoin<examination_info>((em, info) => em.id == info.exam_id
|
|||
|
&& info.userid == 1)
|
|||
|
.Select((em, info) => new examination_info
|
|||
|
{
|
|||
|
id = info.id,
|
|||
|
exam_id = em.id,
|
|||
|
myanswer = info.myanswer,
|
|||
|
score = info.score,
|
|||
|
submit_time = info.submit_time,
|
|||
|
userid = info.userid,
|
|||
|
exam = new examination
|
|||
|
{
|
|||
|
id = em.id,
|
|||
|
answer = em.answer,
|
|||
|
|
|||
|
options = em.options,
|
|||
|
qtype = em.qtype,
|
|||
|
question = em.question
|
|||
|
}
|
|||
|
|
|||
|
})
|
|||
|
.ToList();
|
|||
|
Db.DbMaintenance.TruncateTable<examination>();
|
|||
|
if (exam_info_list.First().exam.options == null)
|
|||
|
{
|
|||
|
throw new Exception("unit error");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static SqlSugarClient GetSqlSugarClient()
|
|||
|
{
|
|||
|
//string connstr = ConfigurationManager.ConnectionStrings["dbconnstr"].ConnectionString;
|
|||
|
string connstr = "server=localhost;Database=SqlSugar5xTest;Uid=root;Pwd=123456;AllowLoadLocalInfile=true";
|
|||
|
//创建数据库对象 (用法和EF Dappper一样通过new保证线程安全)
|
|||
|
SqlSugarClient Db = new SqlSugarClient(new ConnectionConfig()
|
|||
|
{
|
|||
|
ConnectionString = connstr,
|
|||
|
DbType = DbType.MySql,
|
|||
|
IsAutoCloseConnection = true
|
|||
|
},
|
|||
|
db =>
|
|||
|
{
|
|||
|
db.Aop.OnLogExecuting = (sql, pars) =>
|
|||
|
{
|
|||
|
//获取原生SQL推荐 5.1.4.63 性能OK
|
|||
|
//Console.WriteLine(UtilMethods.GetNativeSql(sql, pars));
|
|||
|
//WebLogger.Debug(UtilMethods.GetNativeSql(sql, pars));
|
|||
|
//获取无参数化SQL 对性能有影响,特别大的SQL参数多的,调试使用
|
|||
|
Console.WriteLine(UtilMethods.GetSqlString(DbType.SqlServer, sql, pars));
|
|||
|
};
|
|||
|
|
|||
|
});
|
|||
|
return Db;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|