尝试使用LINQ更新记录时收到比较错误消息。
var tools = from tl in MVCWebsite.MvcApplication.DataContext.tblTools
where tl.pk_fk_Environment == model.Environment
&& tl.pk_fk_Classification == model.Classification
&& tl.pk_ToolNumber == model.ToolNumber
select tl;
Models.Database.tblTool updatingTool = tools.First();
//try
//{
if (createPerson(model.ToolEngineer, true) != null)
updatingTool.fk_Engineer = model.ToolEngineer;
else
updatingTool.fk_Engineer = null;
updatingTool.fk_BuiltBy = model.ToolBuiltBy;
if (createPerson(model.ToolBuiltBy, true) != null)
updatingTool.fk_BuiltBy = model.ToolBuiltBy;
else
updatingTool.fk_BuiltBy = null;
if (createPerson(model.ToolDesignedBy, true) != null)
updatingTool.fk_Designer = model.ToolDesignedBy;
else
updatingTool.fk_Designer = null;
updatingTool.DateOfBuild = model.DateOfBuild;
updatingTool.Machine_Name_Primary = model.ToolPrimaryMachineName;
updatingTool.Machine_Description_Primary = model.ToolPrimaryMachineDescription;
updatingTool.Machine_Name_Secondary = model.ToolSecondaryMachineName;
updatingTool.Machine_Description_Secondary = model.ToolSecondaryMachineDescription;
updatingTool.MERNumber = model.MERNumber;
updatingTool.AssetNumber = model.AssetNumber;
updatingTool.Additional_Cavities = model.AdditionalFields.Cavities;
updatingTool.Additional_Gate = model.AdditionalFields.TypeOfGate;
updatingTool.Additional_Shrinkage = model.AdditionalFields.Shrinkage;
updatingTool.Additional_DieClearance = model.AdditionalFields.DieClearance;
updatingTool.Additional_Field1 = model.AdditionalFields.Additional1;
updatingTool.Additional_Field2 = model.AdditionalFields.Additional2;
updatingTool.Additional_Field3 = model.AdditionalFields.Additional3;
updatingTool.Additional_Field4 = model.AdditionalFields.Additional4;
updatingTool.Additional_OtherInformation = model.AdditionalFields.OtherInformation;
(以下是创建用户功能)
private Models.Database.tblPerson createPerson(string user)
{
if (user == null || user == "")
return null;
var people = from p in MVCWebsite.MvcApplication.DataContext.tblPersons
where p.pk_PersonID == user
select p;
if (people.Count() == 1)
{
return people.First();
}
else
{
Models.UserInformation ui;
ui = MVCWebsite.MvcApplication.DisplayUser(user);
if (!ui.Exists)
return null;
tblPerson person = new tblPerson()
{
pk_PersonID = user,
FirstName = ui.GivenName,
LastName = ui.Surname,
Email = ui.EmailAddress
};
return person;
}
}
我并不担心我的代码目前是否干净,我只是得到了这个错误,它开始让我恼火。
这是主表脚本作为创建(所以你可以看到字段设置:
CREATE TABLE [dbo].[tblTool](
[pk_fk_Environment] [varchar](2) COLLATE Latin1_General_CI_AS NOT NULL,
[pk_fk_Classification] [varchar](3) COLLATE Latin1_General_CI_AS NOT NULL,
[pk_fk_Style] [varchar](4) COLLATE Latin1_General_CI_AS NULL,
[pk_ToolNumber] [int] NOT NULL,
[DateOfBuild] [datetime] NULL,
[fk_Engineer] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[fk_Designer] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[fk_BuiltBy] [varchar](20) COLLATE Latin1_General_CI_AS NULL,
[MERNumber] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[AssetNumber] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[fk_Material] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[fk_LocationCompany] [varchar](20) COLLATE Latin1_General_CI_AS NULL,
[fk_LocationCountry] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[fk_LocationRegion] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[fk_Status] [varchar](10) COLLATE Latin1_General_CI_AS NULL,
[Machine_Name_Primary] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[Machine_Description_Primary] [text] COLLATE Latin1_General_CI_AS NULL,
[Machine_Name_Secondary] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[Machine_Description_Secondary] [text] COLLATE Latin1_General_CI_AS NULL,
[OldToolID] [varchar](100) COLLATE Latin1_General_CI_AS NULL,
[Additional_Cavities] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[Additional_Gate] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[Additional_Shrinkage] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[Additional_DieClearance] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[Additional_Field1] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[Additional_Field2] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[Additional_Field3] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[Additional_Field4] [varchar](50) COLLATE Latin1_General_CI_AS NULL,
[Additional_OtherInformation] [text] COLLATE Latin1_General_CI_AS NULL,
CONSTRAINT [PK_tblTool] PRIMARY KEY CLUSTERED
(
[pk_fk_Environment] ASC,
[pk_fk_Classification] ASC,
[pk_ToolNumber] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
使用相同的信息更新字段时,我收到错误:
SQL Server does not handle comparison of NText, Text, Xml, or Image data types.
有人知道为什么会这样吗?
谢谢, 奥利弗
答案 0 :(得分:1)
将已弃用的Additional_OtherInformation
数据类型中的Machine_Description_Primary
,Machine_Description_Secondary
和TEXT
列更改为VARCHAR(MAX)
数据类型。刷新列映射,您应该全部设置。