igor-tkachev / bltoolkit

Business Logic Toolkit for .NET
MIT License
296 stars 112 forks source link

Invalid SQL generated after C# dll obfuscation #361

Closed NikolayXHD closed 8 years ago

NikolayXHD commented 9 years ago

Generated sql uses C# variable and field names in generated sql code. As a result after a dll is obfuscated, the generated SQL queries do not compile.

Example code: public AccountUser GetAccountUser(Guid userId, Guid accountId) { using (var db = createDbManager()) { var result = db.GetTable().FirstOrDefault(au => au.UserId == userId && au.AccountId == accountId); Console.WriteLine(db.LastQuery); return result; } }

Output: SELECT TOP (1) [au].[Id], [au].[AccountId], [au].[UserId] FROM [Auth].[AccountUsers] [au] WHERE [au].[UserId] = @p1 AND [au].[AccountId] = @accountId1

@accountId1 would change to invalid identifier after obfuscation

BlToolkit version: 4.1.21 Data provider: Sql2008DataProvider

stsrki commented 9 years ago

You need to define mapping attributes for your entities. For example:

[TableName( Name = "TableName", Owner = "SchemaName" )]
public class TableName
{
    [MapField( "TableNameID" ), Identity( IsIdentity = true, OnInsert = true )]
    public int TableNameID { get; set; }

    [MapField( "SomeName" )]
    public string SomeName { get; set; }
}
ili commented 9 years ago

please can you provide SQL query text generated after an obfuscation? or problem is closed with @stsrki recommendations (in general they should help)