为什么会报错呢?
生成的语句中 set 字段前会带有表名,执行报错,类似下面
UPDATE [Users] SET [Users].[PassWord]='10' WHERE [Users].[Id]=1
有人执行成功过么?
报什么错?
PS:后来就不封装dapper了.直接用ormlite了.
near ".": syntax error
ormlite 是在安卓开发用的吧,我是用c#
@simadi: https://github.com/ServiceStack/ServiceStack.OrmLite
UPDATE [Users] SET [PassWord]='10' WHERE [Id]=1
你这样试试
@吴瑞祥: 这样是可以的,只不过那个语句是第三方生成的.我没法改
@simadi: 就是sqlite不支持这个语法.所以orm都是要对不同的数据库做适配的.
你这个扩展不支持sqlite就是
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方法。
好的 谢谢
@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 只是提取一些方法加入自己封装的库里面