Author: Victor.X.Qu
Email: fs7744@hotmail.com
DataAccess is a c# project for sql data mapPing to object,like dapper
DataAccess is for net core,so it base on netstandard1.3
db supportsDataAccess base on ado.net,so you can use blow db :
MSSqlMySqlPostgreSQLSQLiteuse MSsql exampleUse config filedependencIEs "dependencIEs": { "VIC.DataAccess.MSsql": "1.0.1","VIC.DataAccess.Config": "1.0.1" },
You can config sql in xml file for DataAcces,like:
<?xml version="1.0" enCoding="utf-8"?><DbConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <ConnectionStrings> <DataConnection name="Test" ConnectionString="Data Source=(localdb)\MSsqlLocalDB;Initial Catalog=TestDataAccess;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReaDWrite;MultisubnetFailover=False" /> </ConnectionStrings> <sqlConfigs> <Dbsql Commandname="SelectByname" Type="Text" Connectionname="Test"> <Text> <![cdaTA[SELECT top 1 ID,Age,name,JoinDate,[Money]FROM [dbo].[Students] WITH(NolOCK)WHERE @name = name ]]> </Text> <PreParameters> <Parameter name="@name" Direction="input" Type="AnsiString" /> </PreParameters> </Dbsql> <Dbsql Commandname="SelectAll" Type="Text" Connectionname="Test"> <Text> <![cdaTA[SELECT ID,[Money]FROM [dbo].[Students] WITH(NolOCK) ]]> </Text> </Dbsql> <Dbsql Commandname="SelectAllAge" Type="Text" Connectionname="Test"> <Text> <![cdaTA[SELECT sum(Age) as AgeFROM [dbo].[Students] WITH(NolOCK) ]]> </Text> </Dbsql> <Dbsql Commandname="Clear" Type="Text" Connectionname="Test"> <Text> <![cdaTA[delete from [dbo].[Students] ]]> </Text> </Dbsql> <Dbsql Commandname="Bulkcopy" Type="Text" Connectionname="Test"> <Text> <![cdaTA[[dbo].[Students] ]]> </Text> </Dbsql> </sqlConfigs></DbConfig>
Code for use :
var provIDer = new ServiceCollection() .UseDataAccess() .UseDataAccessConfig(Directory.GetCurrentDirectory(),false,"db.xml") .BuildServiceProvIDer();List<Student> students = GenerateStudents(count);var db = provIDer.GetService<IDbManager>(); var command = db.GetCommand("Bulkcopy");await command.ExecuteBulkcopyAsync(students);var command = db.GetCommand("SelectByname");Student s = await command.ExecuteEntityAsync<Student>(new { name = "3" });var command = db.GetCommand("SelectAll");List<Student> students = await command.ExecuteEntityListAsync<Student>();var command = db.GetCommand("SelectAllAge");int? age = await command.ExecuteScalarasync<int?>();
No config filedependencIEs "dependencIEs": { "VIC.DataAccess.MSsql": "1.0.1" },
var provIDer = new ServiceCollection() .UseDataAccess() .BuildServiceProvIDer();var command = provIDer.GetService<IDataCommand>(); command.ConnectionString = "sqlConnectionString";command.Text = "sql";command.Type = CommandType.Text;Student s = await command.ExecuteEntityAsync<Student>(new { name = "3" });
Test performanceYou can see the simple code in https://github.com/fs7744/DataAccess/blob/master/example/MSSqlExample
All packageVIC.ObjectConfigVIC.DataAccessVIC.DataAccess.ConfigVIC.DataAccess.MSSqlVIC.DataAccess.MySqlVIC.DataAccess.PostgreSQLVIC.DataAccess.SQLite 总结以上是内存溢出为你收集整理的又一个类dapper轮子:VIC.DataAccess全部内容,希望文章能够帮你解决又一个类dapper轮子:VIC.DataAccess所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)