DynamicData / LinqtoSql使用triggers和nullable int列 [英] DynamicData / LinqtoSql using triggers and nullable int columns

查看:66
本文介绍了DynamicData / LinqtoSql使用triggers和nullable int列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DynamicData项目,它在表中有一个特定的列,它是一个可以为空的int类型,并将用作一系列数字来跟踪入库货运事务。
我创建了一个触发器来插入值关于将记录插入表格的这一栏。


ALTER





触发器 [dbo] [Inbounds $ InsertTrigger] on [dbo] [Inbounds]



而不是





插入


开始






声明 @ibno < span style ="color:#0000ff; font-size:x-small"> as int





set @ibno = 选择 MAX IB_NO



FROM Inbounds





if @ibno null





set @ibno = 1





insert into Inbounds < font size = 2>



选择 DeliveryDate VendorID PO_NO IB_NO = @ibno 发货人 直径 Qty_Length Qty_Type CustID JobID 来自 INSERTED



结束

这通过插入记录时工作正常SSMS但在通过DynamicData页面插入时失败。错误是'无法将null值分配给类型为System.Int32的成员,这是一个不可为空的值类型。

我的印象是DynamicData处理了nullable int类型就好了。我错了还是我错过了某个地方的设置?
一个人


解决方案

嗨迈克,


欢迎使用MSDN论坛!


您是否尝试修改某个Int32类型列以进行输入诠释? .dbml文件中的(System.Nullable< int>)?



有美好的一天!



最好的问候,
灵芝


I have a DynamicData project that has a particular column in a table which is a nullable int type and will be used as a sequence of numbers to track inbound freight transactions.
I created a trigger to insert the value for this column on inserting the record into the table.

ALTER

 

trigger [dbo].[Inbounds$InsertTrigger] on [dbo].[Inbounds]

instead

 

of insert

as

begin

 

declare @ibno as int

 

set @ibno = (select MAX(IB_NO)

 

FROM Inbounds)

 

if @ibno is null

 

set @ibno = 1

 

 

insert into Inbounds

 

select DeliveryDate,VendorID, PO_NO, IB_NO = @ibno , Shipper, Diameter, Wall, Qty_Length, Qty_Type, CustID, JobID from INSERTED

end

This works fine when inserting a record via SSMS but fails when inserting via the DynamicData page.  The error is 'The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type.

I was under the impression that DynamicData handled nullable int types just fine.  Am I mistaken or did I miss a setting somewhere?



Mike

解决方案

Hi Mike,

Welcome to MSDN Forums!

Have you tried modifying the certain Int32 type column to type int? (System.Nullable<int>) in the .dbml file?  

 

Have a nice day!

 

Best Regards,
Lingzhi


这篇关于DynamicData / LinqtoSql使用triggers和nullable int列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆