1
Vote

集合对象的批量添加时BUG

description

集合对象的批量添加时,会对字符类型的数据进行截取,只能保存2个中文字或者两个英文字符。

tx.Set<Organization>().Batch<Organization>(data, (a, b) => a.Insert(b));

跟踪代码发现NLite.Data.Driver.OracleODPDriver文件中的InitializeParameter有特殊处理:

switch (sqlType.DbType)
            {
                case DBType.NChar:
                case DBType.NVarChar:
                    {
                        var str = value as string;
                        if (string.IsNullOrEmpty(str))
                            p.Size = 2;
                        else
                            p.Size = str.Length * 2;
                        break;
                    }
                case DBType.Char:
                case DBType.VarChar:
                    {
                        var str = value as string;
                        if (string.IsNullOrEmpty(str))
                            p.Size = 1;
                        else
                            p.Size = str.Length * 1;
                        break;
                    }
                case DBType.Guid:
                    parameter.sqlType = SqlType.Get(DBType.Binary, 16);
                    if (value is Guid)
                        p.Value = ((Guid)value).ToByteArray();
                    else if (value != null)
                        p.Value = (((Guid?)value).Value).ToByteArray();
                    break;
                case DBType.Binary:
                case DBType.Image:
                    if (value is Guid)
                    {
                        p.Value = ((Guid)value).ToByteArray();
                        parameter.sqlType = SqlType.Get(DBType.Binary, 16);
                    }
                    else if (value is Guid?)
                    {
                        p.Value = ((Guid?)value).Value.ToByteArray();
                        parameter.sqlType = SqlType.Get(DBType.Binary, 16);
                    }
                    break;
            }
期望改进

comments