C# Linq到SQL插入失败,nvarchar到bigint
我们正试图用一些二进制数据创建一个记录。我不确定是二进制数据还是别的什么 我们的表格定义如下:C# Linq到SQL插入失败,nvarchar到bigint,c#,sql-server,linq,C#,Sql Server,Linq,我们正试图用一些二进制数据创建一个记录。我不确定是二进制数据还是别的什么 我们的表格定义如下: CREATE TABLE [dbo].[InstitutionEntityIPs]( [InstitutionEntityIPID] [int] IDENTITY(1,1) NOT NULL, [InstitutionEntityID] [uniqueidentifier] NOT NULL, [FromIP] [varchar](39) NULL, [ToIP] [varchar](39) NULL
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探查器显示,试图执行的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;
[global::System.Data.Linq.Mapping.TableAttribute(Name=“dbo.instituteEntityIPS”)]
公共部分类机构实体IP:INotifyPropertyChanged,INotifyPropertyChanged
{
私有静态属性ChangingEventArgs emptyChangingEventArgs=新属性ChangingEventArgs(String.Empty);
私立国际机构实体IPID;
private System.Guid_InstitutionEntityID;
私有字符串_FromIP;
私有字符串_-ToIP;
private System.Nullable(来自ipinteger);
私有系统。可为空的_ToIPInteger;
私人楼宇是活跃的;
private System.DateTime\u DateEntered;
private System.Data.Linq.Binary\u RecordVersion;
private System.Data.Linq.Binary\u from IPBinary;
私有系统.Data.Linq.Binary\u-ToIPBinary;
私人实体REF_机构实体;
什么是InstituteEntityIP
?自定义DTO,或映射表实体的实例(生成的类LINQ to SQL)?它是在我的DBML中生成的类LINQ to SQL。你能在这里包括它的定义吗?添加了它的私有变量。你想要更多吗?有触发器、计算列或类似的吗?