我再次提出另一个 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