Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap Table Names with [ ] #47

Closed
bagzli opened this issue Oct 23, 2017 · 4 comments
Closed

Wrap Table Names with [ ] #47

bagzli opened this issue Oct 23, 2017 · 4 comments

Comments

@bagzli
Copy link

bagzli commented Oct 23, 2017

Hi, I noticed that you don't wrap your table names with [ ]. By that I mean if you query on [dbo].User you will get an error because User is a reserved keyword. However if you query [dbo].[User] then it will work. In any case, I would suggest updating the scripts in the respective projects to wrap those and thus allow people to name their tables however they want without having to change your code too much.

I know you don't have that problem now because you prefixed your table names with Identity, but if I wanted to change those names to my custom names then I will basically rewrite your adapter dlls, but it would be nice not to have to rewrite too much code to make it work and only have to update the variable names where your tables are stored.

@grandchamp
Copy link
Owner

grandchamp commented Oct 25, 2017

Yes, this behavior is just in SQL Server. The property TableFieldNotation on SqlConfiguration it's for this, but it's a single character, and for SQL i have to switch [ for the beggining and ] for the last position. I'll think in something to make this works.

@bagzli
Copy link
Author

bagzli commented Oct 25, 2017

In my case what I did was I rewrote the Identity.Dapper.SqlServer dll. Because I had to change table names, I had to modify this dll, so I just wrote my own as it is a very small dll. When I did that, I simply changed lines of such as this:

GetUserLoginByLoginProviderAndProviderKeyQuery = "SELECT TOP 1 %USERFILTER% FROM %SCHEMA%.%USERTABLE%, %SCHEMA%.%USERLOGINTABLE% WHERE %SCHEMA%.%USERTABLE%.Id = %SCHEMA%.%USERLOGINTABLE%.UserId AND LoginProvider = %LOGINPROVIDER% AND ProviderKey = %PROVIDERKEY%";

To look like this

GetUserLoginByLoginProviderAndProviderKeyQuery = "SELECT TOP 1 %USERFILTER% FROM %SCHEMA%.[%USERTABLE%], %SCHEMA%.%USERLOGINTABLE% WHERE %SCHEMA%.[%USERTABLE%].Id = %SCHEMA%.%USERLOGINTABLE%.UserId AND LoginProvider = %LOGINPROVIDER% AND ProviderKey = %PROVIDERKEY%";

You could resolve it in such way for your dll too, however, I must admit it would be nice being able to set Table Names outside of your dll in some way. Maybe there is and I missed it?

@grandchamp
Copy link
Owner

You can create a class inheriting from SqlServerConfiguration, or declare a new instance of SqlServerConfiguration and change RoleTable, UserTable, UserClaimTable, UserRoleTable and UserLoginTable properties values.

@grandchamp
Copy link
Owner

Not really a fix, but 34f240c does it for the default tables now. If you want to change your table names on SQL Server, you can do:

.AddDapperIdentityFor(new SqlServerConfiguration
{
      RoleTable = "[My Table IdentityRole]",
      UserTable = "[User]";
      UserClaimTable = "[MyIdentityUserClaim]";
      UserRoleTable = "[MyIdentityUserRole]";
      UserLoginTable = "[MyIdentityLogin]";
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants