我再次提出另一个LINQ问题。
我们的数据库已设置好,以便在发生SQL插入时有一个事件触发器。
现在,当我使用LINQ时,没有调用此触发器。有什么特别需要做的事情让数据库看到LINQ命令作为插入吗? (以下代码)。我应该说正确地将数据输入数据库,但触发器没有发生。
提前致谢。
LINQ代码:
private void SaveToWebsure()
{
using (MagTestDataContext context = new MagTestDataContext())
{
//create new instance of tblPolicy object
tblPolicy policy = new tblPolicy();
//generate PolicyID number
policyNo = context.ExecuteQuery<int>("DECLARE @ret INT; EXEC spNextPolicyID @ret OUTPUT; SELECT @ret").Single();
//add values to field
policy.PolicyID = policyNo;
policy.RecordType = "New Business";
policy.SchemeID = 17;
policy.Status = "Quote";
policy.Title = ddTitle.Text + ' ' + tbSurname.Text;
policy.PolicyHolder = ddTitle.Text + ' ' + tbFirstName.Text + ' ' + tbSurname.Text;
policy.SearchKey = tbSurname.Text;
policy.EMail = tbEmail.Text;
policy.Telephone = tbTelephone.Text;
policy.Address1 = tbAddressLine1.Text;
policy.Address2 = tbAddressLine2.Text;
policy.Address3 = tbAddressLine3.Text;
policy.Address4 = tbAddressLine4.Text;
policy.PostCode = tbPostcode.Text;
policy.rowguid = System.Guid.NewGuid();
policy.Comments = "Current/Previous Insurer: " + tbInsurer.Text + "; " + "Reason for refused insurance: " + ddReason.SelectedItem.Text + "; " + "Further reasons specified: " + tbOther.Text;
//insert new contact_detail object
context.tblPolicies.InsertOnSubmit(policy);
//submit changes to database
context.SubmitChanges();
}
存储过程:
ALTER PROCEDURE spNextPolicyID @PolicyID int output AS
begin tran
/* update tblIdNumbers set ApplicantId = ApplicantId
set @Policyid = (select ApplicantID from tblIdNumbers)
update tblIdNumbers set ApplicantId = ApplicantId + 1 */
set Rowcount 0
SET NOCOUNT ON
exec dbo.spNextIdNumber @PolicyID Output,'PolicyId'
commit tran
答案 0 :(得分:0)
LINQ在后台没有做任何特别的事情。你应该检查几件事