/// <summary> /// 部分更新 /// </summary> /// <param name="id">主键</param> /// <param name="entity">实体</param> /// <returns>实体</returns> public TEntity Update(TPrimaryKey id, object entity) { IClassMapper classMapper = DapperConfig.GetMap <TEntity>(); IClassMapper entityMapper = DapperConfig.GetMap(entity.GetType()); var keyName = classMapper.Properties.First(d => d.PropertyInfo.PropertyType == typeof(TPrimaryKey) && d.KeyType != KeyType.NotAKey); var predicate = new FieldPredicate <TEntity> { PropertyName = keyName.Name, Operator = Operator.Eq, Value = id, Not = false }; Dictionary <string, object> parameters = new Dictionary <string, object>(); DynamicParameters dynamicParameters = new DynamicParameters(); string sql = GenerateUpdateSql(classMapper, entityMapper, predicate, parameters); var columns = entityMapper.Properties.Where(p => !(p.Ignored || p.IsReadOnly || p.KeyType == KeyType.Identity)); foreach (var property in ReflectionHelper.GetObjectValues(entity) .Where(property => columns.Any(c => c.Name == property.Key))) { dynamicParameters.Add(property.Key, property.Value); } foreach (var parameter in parameters) { dynamicParameters.Add(parameter.Key, parameter.Value); } Connection.Execute(sql, dynamicParameters, Transaction); return(Get(id)); }
public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc() .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <AuthorValidator>()); DapperConfig.Config(); return(AutofacConfig.Config(services, Configuration)); }
public List <Models.TopologicalGraph> GetAllGraph(string connectionString) { using (IDbConnection conn = DapperConfig.GetSqlConnection(connectionString)) { string querySql = @"SELECT * FROM EnergyDB.TopologicalGraph;"; return(conn.Query <Models.TopologicalGraph>(querySql).ToList()); } }
public List <CollectionData.Models.TopologicalRegister> GetTopologicalRegisters(int id, string connectionString) { using (IDbConnection conn = DapperConfig.GetSqlConnection(connectionString)) { string querySql = @"SELECT MeterCode,ParamCode FROM EnergyDB.TopologicalRegister WHERE ID=@ID;"; return(conn.Query <CollectionData.Models.TopologicalRegister>(querySql, new { ID = id }).ToList()); } }
public RepositoryTests() { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: false) .AddEnvironmentVariables() .Build(); _dapperConfig = new DapperConfig(configuration); }
public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); // Application services.AddAutoMapper(Assembly.GetExecutingAssembly()); // Infrastructure DapperConfig.Init(); services.AddTransient <IHeroRepository, HeroRepository>(); }
public void SetUp() { DropAllTable(); Database.Initialize(_connectionString); DapperConfig.Initialize(); MarkdownParser.RegisterJsEngineType <V8JsEngine>(); var service = new SearchService(_connectionString); service.RecreateEsIndexAsync().Wait(); }
public List <Application.MRegister> GetRegisters(int serverId, string connectionString) { using (IDbConnection conn = DapperConfig.GetSqlConnection(connectionString)) { string querySql = @" SELECT * FROM MRegister WHERE ServerID = @ServerID "; return(conn.Query <Application.MRegister>(querySql, new { ServerID = serverId }).ToList()); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); Database.Initialize(GlobalSettings.DefaultConnectionString); DapperConfig.Initialize(); DefaultTraceLogInitializer.Initialize(GlobalSettings.DefaultConnectionString, TraceLogLevel.Trace); LogManager.RegisterAccessLogger <AccessLogger>(); MappingConfig.CreateMap(); MarkdownParser.RegisterJsEngineType <V8JsEngine>(); }
public virtual void SetUp() { if (!_isDbInitialized) { // テスト初回のみ、すでにDBが存在したらDBを再作成する DropAllTable(); _isDbInitialized = true; } Database.Initialize(ConnectionString); DapperConfig.Initialize(); UserDbCommand.SaveAsync(LogonUser).Wait(); }
public string GetSvgPath(int id, string connectionString) { using (IDbConnection conn = DapperConfig.GetSqlConnection(connectionString)) { string querySql = @"SELECT Path FROM EnergyDB.TopologicalGraph WHERE ID=@ID;"; List <string> result = conn.Query <string>(querySql, new { ID = id }).ToList(); if (result.Count > 0) { return(result[0]); } else { return("error"); } } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Configure Mediator services.AddMediatR(typeof(Startup)); //Register Repositories services.RegisterAllRepositories(typeof(IRepository <>).Assembly); DapperConfig.Configure(services); services.AddAutoMapper(typeof(Infrastructure.Mappers.SourcingMapper), typeof(Mapper)); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Dealer.Sourcing.Api.Private", Version = "v1" }); }); }
public Startup(IConfiguration configuration) { DapperConfig = new DapperConfig(configuration); }
public Dapper(DapperConfig config) { Config = config; }
static DataAccessBase() { // Common DA once-only setup tasts DapperConfig.Configure(); }