app.xaml.cs
SugarIocServices.AddSqlSugar(new IocConfig()
{
ConnectionString = @"DataSource=" + Environment.CurrentDirectory + @"\DataBase\DeviceSystem.sqlite3",
DbType = IocDbType.Sqlite,
IsAutoCloseConnection = true,
}) ;
新建一个基础类
public class BaseRespository<TEntity> : SimpleClient<TEntity>, IRespositoryBase<TEntity> where TEntity : class,new()
{
public BaseRespository(ISqlSugarClient sqlSugarClient = null) : base(sqlSugarClient)
{
if (sqlSugarClient == null)
{
base.Context = DbScoped.Sugar;
base.Context.DbMaintenance.CreateDatabase();
base.Context.CodeFirst.InitTables(
typeof(TaksInfo),
typeof(CaseInfo),
typeof(UserInfo),
typeof(StepInfo),
typeof(StepParam),
typeof(AxisInfo),
typeof(CameraInfo),
typeof(PointInfo)
);
}
}
}
其他类继承这个类就行了
public class TaskInfoRespository:BaseRespository<TaksInfo>,ITaskInfoRespository
{}