首页新闻找找看学习计划

Dapper-Extensions中的update 大家用过么?

0
[已解决问题] 解决于 2017-02-09 10:12

为什么会报错呢?

生成的语句中 set 字段前会带有表名,执行报错,类似下面

 UPDATE [Users] SET [Users].[PassWord]='10' WHERE [Users].[Id]=1

有人执行成功过么?

simadi的主页 simadi | 菜鸟二级 | 园豆:283
提问于:2017-02-08 16:00
< >
分享
最佳答案
0

报什么错?

PS:后来就不封装dapper了.直接用ormlite了.

奖励园豆:5
吴瑞祥 | 高人七级 |园豆:28745 | 2017-02-08 16:15

near ".": syntax error

simadi | 园豆:283 (菜鸟二级) | 2017-02-08 16:15

ormlite 是在安卓开发用的吧,我是用c#

simadi | 园豆:283 (菜鸟二级) | 2017-02-08 16:18

@simadi: https://github.com/ServiceStack/ServiceStack.OrmLite

 UPDATE [Users] SET [PassWord]='10' WHERE [Id]=1

你这样试试

吴瑞祥 | 园豆:28745 (高人七级) | 2017-02-08 17:08

@吴瑞祥: 这样是可以的,只不过那个语句是第三方生成的.我没法改

simadi | 园豆:283 (菜鸟二级) | 2017-02-08 17:09

@simadi: 就是sqlite不支持这个语法.所以orm都是要对不同的数据库做适配的.

你这个扩展不支持sqlite就是

吴瑞祥 | 园豆:28745 (高人七级) | 2017-02-08 19:53
其他回答(1)
0

Dapper-Extensions 是开源的建议你可以阅读以下它的源码

它是基于Dapper的扩展库

关于SQL的组装

https://github.com/tmsmith/Dapper-Extensions/blob/e95787e60f300872110a0cec8de23a1d2272b484/DapperExtensionsDNXCore/Sql/SqlGenerator.cs 

 

你可以做个测试使用Dapper的创建方法应用在Sqlite数据库上面,如果能通过就说明 Dapper-Extensions的组件没支持到Sqlite数据库语法。所以你需要重新继承 ISqlGenerator 

https://github.com/tmsmith/Dapper-Extensions/blob/08663c63c0f4bf8796d80224dd065c70a4b1a830/DapperExtensions/Sql/SqlDialectBase.cs

或者重载GetTableName方法。

 

 

 

 

李小潮 | 园豆:202 (菜鸟二级) | 2017-02-13 13:56

好的 谢谢

支持(0) 反对(0) simadi | 园豆:283 (菜鸟二级) | 2017-02-13 13:57

@simadi: 

Dapper-Extensions 里面发现一个不好的封装·他的查询方法都需要是类型为CLASS

 

public interface IDapperImplementor
  {
  ISqlGenerator SqlGenerator { get; }
  T Get<T>(DbConnection connection, dynamic id, DbTransaction transaction, int? commandTimeout) where T : class;
  void Insert<T>(DbConnection connection, IEnumerable<T> entities, DbTransaction transaction, int? commandTimeout) where T : class;
  dynamic Insert<T>(DbConnection connection, T entity, DbTransaction transaction, int? commandTimeout) where T : class;
  bool Update<T>(DbConnection connection, T entity, DbTransaction transaction, int? commandTimeout) where T : class;
  bool Delete<T>(DbConnection connection, T entity, DbTransaction transaction, int? commandTimeout) where T : class;
  bool Delete<T>(DbConnection connection, object predicate, DbTransaction transaction, int? commandTimeout) where T : class;
  IEnumerable<T> GetList<T>(DbConnection connection, object predicate, IList<ISort> sort, DbTransaction transaction, int? commandTimeout, bool buffered) where T : class;
  IEnumerable<T> GetPage<T>(DbConnection connection, object predicate, IList<ISort> sort, int page, int resultsPerPage, DbTransaction transaction, int? commandTimeout, bool buffered) where T : class;
  IEnumerable<T> GetSet<T>(DbConnection connection, object predicate, IList<ISort> sort, int firstResult, int maxResults, DbTransaction transaction, int? commandTimeout, bool buffered) where T : class;
  int Count<T>(DbConnection connection, object predicate, DbTransaction transaction, int? commandTimeout) where T : class;
  IMultipleResultReader GetMultiple(DbConnection connection, GetMultiplePredicate predicate, DbTransaction transaction, int? commandTimeout);
  }

 

https://github.com/tmsmith/Dapper-Extensions/blob/e95787e60f300872110a0cec8de23a1d2272b484/DapperExtensionsDNXCore/DapperImplementor.cs

 

所以我都是直接Dapper上面封装没用

Dapper-Extensions 只是提取一些方法加入自己封装的库里面

支持(0) 反对(0) 李小潮 | 园豆:202 (菜鸟二级) | 2017-02-13 14:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册