igor-tkachev / bltoolkit

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

Parameter name contains space symbol #380

Closed ras254 closed 8 years ago

ras254 commented 8 years ago

Db: MS SQL 2008 Wrong parameter name (with space) if column name contains space also.

For this operation DbManager.Update(IEnumerable<T>);

Incorrect syntax near 'nvarchar'. Must declare the scalar variable "@Record". Statement(s) could not be prepared.

  в BLToolkit.Data.DbManager.OnOperationException(OperationType op, DataException ex)
   в BLToolkit.Data.DbManager.HandleOperationException(OperationType op, Exception ex)
   в BLToolkit.Data.DbManager.ExecuteOperation[T](OperationType operationType, Func`1 operation)
   в BLToolkit.Data.DbManager.ExecuteNonQueryInternal()
   в BLToolkit.Data.DbManager.ExecuteForEach[T](IEnumerable`1 collection, MemberMapper[] members, Int32 maxBatchSize, ParameterProvider`1 getParameters)
   в BLToolkit.DataAccess.SqlQuery`1.ExecuteForEach(DbManager db, IEnumerable`1 collection, MemberMapper[] members, Int32 maxBatchSize, ParameterProvider`1 getParameters)
   в BLToolkit.DataAccess.SqlQuery`1.Update(DbManager db, Int32 maxBatchSize, IEnumerable`1 list)
   в BLToolkit.Data.Linq.Extensions.Update[T](DbManager dataContext, Int32 maxBatchSize, IEnumerable`1 list)
   в BLToolkit.Data.Linq.Extensions.Update[T](DbManager dataContext, IEnumerable`1 list)

Update: this is a problem code... https://github.com/igor-tkachev/bltoolkit/blob/master/Source/Data/Sql/SqlProvider/MySqlSqlProvider.cs#L197

ili commented 8 years ago

can you provide the sample?

ras254 commented 8 years ago

Data model

    [TableName("doc")]
    public class Doc
    {
        [PrimaryKey, NotNull, MapField("Record Number")]
        public String Id { get; set; }

        [MapField("Subject"), Nullable]
        public String Subject { get; set; }

        [MapField("Record Title"), Nullable]
        public String RecordTitle { get; set; }
    }

Problem code

            using (var db = new DbManager(new Sql2008DataProvider(), connectionString))
            {
                var docs = db.GetTable<Doc>().Where(d => d.Id == "000").ToList();
                db.Update((IEnumerable<Doc>)docs); // Exception here
            }

Db table

CREATE TABLE [dbo].[doc](
    [Record Number] [nvarchar](255) NOT NULL,
    [Subject] [nvarchar](255) NULL,
    [Record Title] [nvarchar](255) NULL
,
 CONSTRAINT [doc$PrimaryKey] PRIMARY KEY CLUSTERED 
(
    [Record Number] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
ili commented 8 years ago

please, check and close issue if fixed

ras254 commented 8 years ago

Fixed, thanks