public static void Config() { string ConnectionString = "Data Source=(Local);Initial Catalog=Northwind;User ID=test;Password=test"; var connectionProvider = new ConnectionStringConnectionProvider(ConnectionString); MsSqlRepoFactory.UseConnectionProvider(connectionProvider); }
/// <summary> /// init /// 创建初始方法,初始一个工厂类。 /// </summary> static void Init() { // Set Connection String string ConnectionString = "Data Source=(Local);Initial Catalog=Northwind;User ID=test;Password=test"; var connectionProvider = new ConnectionStringConnectionProvider(ConnectionString); MsSqlRepoFactory.UseConnectionProvider(connectionProvider); // this Demo is POJO ,So Using SimpleWritablePropertyMatcher()。 // 本例中,使用的是简单类,所以用SimpleWritablePropertyMatcher()来操作属性。 MsSqlRepoFactory.UseWritablePropertyMatcher(new SimpleWritablePropertyMatcher()); }
private static void Main(string[] args) { var connectionProvider = new AppConfigFirstConnectionProvider(); MsSqlRepoFactory.UseConnectionProvider(connectionProvider); MsSqlRepoFactory.UseStatementTransactionExecutor(); var gettingStarted = new GettingStarted(); // gettingStarted.DoIt(); // gettingStarted.DoItJoin(); gettingStarted.DoItUnion(); // gettingStarted.DoItUpdata(); //gettingStarted.DoItNested(); //gettingStarted.DoItTaskRemark(); Console.ReadLine(); }
public static void TestMsSql() { string ConnectionString = "Data Source=(Local);Initial Catalog=Northwind;User ID=test;Password=test"; var connectionProvider = new MsSQLP.ConnectionStringConnectionProvider(ConnectionString); MsSqlRepoFactory.UseConnectionProvider(connectionProvider); MsSqlRepoFactory.UseStatementExecutor(new DapperStatementExecutor(connectionProvider)); MsSqlRepoFactory.UseDataReaderEntityMapper(new DapperEntityMapper()); var repository = MsSqlRepoFactory.Create <Customers>(); var result = repository.Query().Select(e => e.CustomerID, e => e.CompanyName, e => e.Address).Top(10); Console.WriteLine(result.Sql()); var rs = result.Go(); foreach (var r in rs) { Console.WriteLine($"{r.CustomerID}\t {r.CompanyName}\t\t\t {r.Address}"); } }