PomeloFoundation / Lolita

A light-weight extension which provides bulk update and delete operations for Entity Framework Core.
MIT License
118 stars 23 forks source link

SqliteException : SQLite Error 1: 'near ".": syntax error'. #6

Open brusw opened 7 years ago

brusw commented 7 years ago

使用Pomelo.EntityFrameworkCore.Lolita无法生成正确的sql更新语句: image 通过GenerateBulkUpdateSql方法查看生成的sql语句如下:

UPDATE "Bulletin"
SET "Bulletin"."Content" = {0}
WHERE ("Bulletin"."BulletinId" = 1) AND ("Bulletin"."IsDeleted" = 0);
atagirov commented 7 years ago

Same problem for PostrgeSQL, i fix this by reimplementing ParseField method in IFieldParser:

public class PostgreSQLFieldParser: DefaultFieldParser
{
    private readonly ISqlGenerationHelper _sqlGenerationHelper;

    public PostgreSQLFieldParser(
            ICurrentDbContext currentDbContext, 
            ISqlGenerationHelper sqlGenerationHelper, 
            IDbSetFinder dbSetFinder)
        : base(currentDbContext, sqlGenerationHelper, dbSetFinder)
    {
        _sqlGenerationHelper = sqlGenerationHelper;
    }

    public override string ParseField(SqlFieldInfo field)
    {
        // just column name, without table name
        return _sqlGenerationHelper.DelimitIdentifier(field.Column);
    }
}

And after using this implementation instead DefaultFieldParser:

services.AddDbContext<MyDbContext>(opts =>
{
    opts.UseNpgsql(Configuration.GetConnectionString("MyDatabase"));
    opts.UsePostgreSQLLolita();
    opts.ReplaceService<IFieldParser, PostgreSQLFieldParser>(); // replace
});

I don't know, planing some changes in this library in future...