我们正在尝试使用一些二进制数据创建记录。我不确定它是二进制数据还是别的。
我们的表定义如下:
CREATE TABLE [dbo].[InstitutionEntityIPs](
[InstitutionEntityIPID] [int] IDENTITY(1,1) NOT NULL,
[InstitutionEntityID] [uniqueidentifier] NOT NULL,
[FromIP] [varchar](39) NULL,
[ToIP] [varchar](39) NULL,
[FromIPInteger] [bigint] NULL,
[ToIPInteger] [bigint] NULL,
[IsActive] [bit] NOT NULL,
[DateEntered] [datetime] NOT NULL CONSTRAINT [DF_tempInstitutionEntityIPs_DateEntered] DEFAULT (getdate()),
[RecordVersion] [timestamp] NOT NULL,
[FromIPBinary] [varbinary](16) NULL,
[ToIPBinary] [varbinary](16) NULL
我们的C#代码如下所示:
db.InstitutionEntityIPs.InsertOnSubmit(institutionEntityIp);
db.SubmitChanges();
SQL Profiler显示尝试执行的SQL是:
exec sp_executesql N'INSERT INTO [dbo].[InstitutionEntityIPs](
[InstitutionEntityID], [FromIP], [ToIP], [FromIPInteger], [ToIPInteger],
[IsActive], [DateEntered], [FromIPBinary], [ToIPBinary])
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8)',
N'@p0 uniqueidentifier,@p1 varchar(8000),@p2 varchar(8000),
@p3 bigint,@p4 bigint,@p5 bit,@p6 datetime,
@p7 varbinary(max) ,@p8 varbinary(max) ',
@p0='06E82E96-CE8D-4D2A-B1F3-BD606C2BD021',
@p1='2001:db8:ac10:fe01::',
@p2='2001:db8:ac10:fe01::1:0',
@p3=0,
@p4=0,
@p5=1,
@p6='2015-05-28 12:41:35.873',
@p7=0x20010DB8AC10FE010000000000000000,
@p8=0x20010DB8AC10FE010000000000000000
SQL说:将数据类型nvarchar转换为bigint时出错。
我尝试使用有限的数据进行SQL插入,但仍然收到相同的消息。
DECLARE @p0 uniqueidentifier,
@p1 varchar(8000),
@p2 varchar(8000),
@p3 bigint,
@p4 bigint,
@p5 bit,
@p6 datetime,
@p7 varbinary(max) ,
@p8 varbinary(max)
SELECT @p0='06E82E96-CE8D-4D2A-B1F3-BD606C2BD021',
@p1=N'2001:db8:ac10:fe01::',
@p2=N'2001:db8:ac10:fe01::1:0',
@p3=0,
@p4=0,
@p5=1,
@p6='2015-05-28 12:41:35.873',
@p7=0x20010DB8AC10FE010000000000000000,
@p8=0x20010DB8AC10FE010000000000000000
INSERT INTO [dbo].[InstitutionEntityIPs](
[InstitutionEntityID], [FromIP], [ToIP],
[IsActive])
VALUES (@p0, @p1, @p2,
@p5)
它看到nvarchar并试图加入bigint是什么?
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.InstitutionEntityIPs")]
public partial class InstitutionEntityIP : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
private int _InstitutionEntityIPID;
private System.Guid _InstitutionEntityID;
private string _FromIP;
private string _ToIP;
private System.Nullable<long> _FromIPInteger;
private System.Nullable<long> _ToIPInteger;
private bool _IsActive;
private System.DateTime _DateEntered;
private System.Data.Linq.Binary _RecordVersion;
private System.Data.Linq.Binary _FromIPBinary;
private System.Data.Linq.Binary _ToIPBinary;
private EntityRef<InstitutionEntity> _InstitutionEntity;