.Net Editor Sql Square brackets fail request

.Net Editor Sql Square brackets fail request

klymov.inekonklymov.inekon Posts: 11Questions: 1Answers: 0

Hello.
I have a problem from server side .net sql request via editor. I have table named User. Add it as usual with primary key Id.
new Editor(db, "dbo.User", ["dbo.User.Id"])
But User is functional word for sql request. So it doesn't work. I have first debug request.
SELECT COUNT( dbo.User.id ) as 'cnt' FROM [dbo].[User] WHERE (1=1)
Error in COUNT( dbo.User.id ) Request see User as specific word, not as a table name.
So I need to write square brackets around User and it will understand User as table name.
I change it in Editor request like
new Editor(db, "dbo.User", ["[dbo].[User].Id"])
and request go futher but last request has error

SELECT [[dbo]].[[User]].[ID] as '[dbo].[User].ID', [dbo].[User].[ID] as 'dbo.User.ID', ...
and has brackets twice.
How can I avoid it?

Replies

  • allanallan Posts: 63,966Questions: 1Answers: 10,546 Site admin

    Try:

    new Editor(db, "dbo.User",  "Id")
    

    Editor will add the square brackets to protect the identifiers automatically).

    Allan

  • klymov.inekonklymov.inekon Posts: 11Questions: 1Answers: 0

    in this case sometimes it doesn't work. if I have some left join with same column name it will give an error. I have dynamic table editor and don't know which columns will be. Solution for this was writing table name and schema

  • klymov.inekonklymov.inekon Posts: 11Questions: 1Answers: 0

    I have tested this again and now it work. I not sure why it changed. Before it didn't work without it. If I find this problem again - I will add problem here

  • allanallan Posts: 63,966Questions: 1Answers: 10,546 Site admin

    Good to hear it is working at the moment. Thanks for the update.

    Allan

Sign In or Register to comment.