在模式中覆盖AllowNull的最佳方法? [英] Best way to override AllowNull in a schema?

查看:62
本文介绍了在模式中覆盖AllowNull的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Oracle数据库创建一个CRUD屏幕...但问题是

该表中的主键是通过自动编号填充的,在
$ b中$ b Oracle仅使用触发器和序列完成。我只想说,即使出现了这个专栏,这个专栏也没有意识到,这个专栏是可选的 - 这是创建新行时的一个问题。我想知道

删除约束的最佳方法是什么?假设与ADO.Net直接接触,我已经多次被咬过了很多次 - 很多隐藏的陷阱也是如此。我的第一直觉就是设置数据列'<​​br />
AllowDBNull属性 - 但是约束仍然会爆炸

GetChanges() - 我正在检查它如果有任何真正的限制因为违反了b $ b。


任何指针?

解决方案

嗨Martin,


通常,人们只需将序列列中的AutoIncrement,ReadOnly和Unique全部设置为true即可。


但是,我不是Oracle用户,但我知道这种方法适用于Sql Server中的自动编号的
自动编号列。我无法想象它与甲骨文有什么不同,因为这里的问题实际上是处理ADO.NET如何处理

概念,无论RDBMS如何。 />

-

Dave Sexton


" Martin Z" < ma *********** @ gmail.comwrote in message

news:11 ******************* ***@j44g2000cwa.googlegr oups.com ...


我正在为Oracle数据库制作一个CRUD屏幕......但是问题在于/>
该表中的主键是通过自动编号填充的,其中

Oracle仅使用触发器和序列完成。我只想说,即使出现了这个专栏,这个专栏也没有意识到,这个专栏是可选的 - 这是创建新行时的一个问题。我想知道

删除约束的最佳方法是什么?假设与ADO.Net直接接触,我已经多次被咬过了很多次 - 很多隐藏的陷阱也是如此。我的第一直觉就是设置数据列'<​​br />
AllowDBNull属性 - 但是约束仍然会爆炸

GetChanges() - 我正在检查它如果有任何真正的限制因为违反了b $ b。


任何指针?


只是给了一个镜头,自动增量的一些变化

属性 - 它似乎不允许违反约束,

和确定

适当的插入值似乎并不足够聪明。


我想我必须放弃并使用它EnforceConstraints = false。

最好在我可以使用的数据库更新中获得错误

冒着应用程序陷入某种状态的风险
当数据库

无论如何都会覆盖它时,
无法找出主键的有效值。


谢谢然而,指针。希望我们将来会在某个时候使用SQL Server

,然后我就可以从ADO.Net的

不完美映射中逃脱Oracle。


Dave Sexton写道:


嗨马丁,


通常,只需将序列列中的AutoIncrement,ReadOnly和Unique全部设置为true即可。


我不是Oracle用户,但是,我知道这种方法适用于Sql Server中的

自动编号列。我无法想象它与甲骨文有什么不同,因为这里的问题实际上是处理ADO.NET如何处理

概念,无论RDBMS如何。 />

-

Dave Sexton


" Martin Z" < ma *********** @ gmail.comwrote in message

news:11 ******************* ***@j44g2000cwa.googlegr oups.com ...


我正在为Oracle数据库制作一个CRUD屏幕......但是问题在于/>
该表中的主键是通过自动编号填充的,其中

Oracle仅使用触发器和序列完成。我只想说,即使出现了这个专栏,这个专栏也没有意识到,这个专栏是可选的 - 这是创建新行时的一个问题。我想知道

删除约束的最佳方法是什么?假设与ADO.Net直接接触,我已经多次被咬过了很多次 - 很多隐藏的陷阱也是如此。我的第一直觉就是设置数据列'<​​br />
AllowDBNull属性 - 但是约束仍然会爆炸

GetChanges() - 我正在检查它如果有任何真正的限制因为违反了b $ b。


任何指针?


嗨Martin,


>通常,只需将序列列中的AutoIncrement,ReadOnly和Unique都设置为true

我不是Oracle用户,但是我知道这种方法适用于Sql Server中的自动编号列。我无法想象它与甲骨文有什么不同,因为这里的问题实际上是在处理ADO.NET如何处理这个概念,无论RDBMS如何。



只是给了一个镜头,自动增量的一些变化

属性 - 它似乎不允许约束被违反,



但这应该是一件好事;)


并且它不会似乎足够聪明,以确定插入的适当值




不,它根本没有插入那个值,因为它代表一个有序的列

,它有一个由Oracle生成的值。它的目的是在DataTable中提供一个唯一的密钥作为占位符,直到将数据插入数据库,在这种情况下,DataRow应该是更新为

正确,Oracle生成的值。


我想我必须放弃并使用EnforceConstraints =假。



Eeek。


最好在数据库更新时出错,我可以使用

冒着应用程序陷入某种状态的风险

数据库时无法确定主键的有效值

无论如何都会覆盖它。



数据库不应该覆盖任何东西,因为在插入过程中,数值不应该是提供给数据库的
,因为它毫无意义。然而,

值应该在DataRow中从数据源本身更新

插入后。


当你插入记录,你应该使用Oracle生成的新的

序列值返回结果集:


- T-SQL,但希望你会得到这个想法:


INSERT表SELECT @ non_key_1,@ non_key_2;


SELECT键,non_key_1,non_key_2 FROM表

WHERE key = SCOPE_IDENTITY();

当InsertCommand的UpdatedRowSource时,DbDataAdapter应该自动处理底层DataRow

的更新属性设置为适当的
(SqlCommand默认为Both)。


我不确定OracleDataAdapter是否提供此功能,但它'这是值得测试的
。如果甲骨文没有提供这种能力那么我就不会确定你能做什么。


感谢指点,虽然。希望我们将来会在某个时候使用SQL Server

,然后我就可以从ADO.Net的

不完美映射中逃脱甲骨文。



NP,GL;)


-

Dave Sexton


I''m making a CRUD screen for an Oracle database... but problem is that
the primary key in that table is populated via an autonumber, which in
Oracle is done just with triggers and sequences. Suffice to say that
ADO.Net 1.1 is unaware that this column is, despite appearances,
optional - which is a problem when creating new rows. I was wondering
what the best way to remove the constraint is? I''ve been bitten too
many times by assuming the direct approach with ADO.Net - there are too
many hidden gotchas. My first instinct is to just set the datacolumn''s
AllowDBNull property - but the constraint still blows up on
GetChanges() - which I''m using to check if any real constraints are
being violated.

Any pointers?

解决方案

Hi Martin,

Commonly, one would just set AutoIncrement, ReadOnly and Unique all to true on
the sequenced column.

I''m not an Oracle user, however, but I know this approach works with
auto-numbered columns in Sql Server. I can''t imagine it being different from
Oracle since the issue here is really dealing with how ADO.NET handles that
concept, regardless of the RDBMS.

--
Dave Sexton

"Martin Z" <ma***********@gmail.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...

I''m making a CRUD screen for an Oracle database... but problem is that
the primary key in that table is populated via an autonumber, which in
Oracle is done just with triggers and sequences. Suffice to say that
ADO.Net 1.1 is unaware that this column is, despite appearances,
optional - which is a problem when creating new rows. I was wondering
what the best way to remove the constraint is? I''ve been bitten too
many times by assuming the direct approach with ADO.Net - there are too
many hidden gotchas. My first instinct is to just set the datacolumn''s
AllowDBNull property - but the constraint still blows up on
GetChanges() - which I''m using to check if any real constraints are
being violated.

Any pointers?



Just gave that a shot, with a few variations on the autoincrement
properties - it doesn''t seem to allow the constraint to be violated,
and it doesn''t seem to be sufficiently intelligent to determine
appropriate values for the insertion.

I think I''ll have to give up and use EnforceConstraints = false.
Better to get an error on database update that I can work with than
risk the application getting trapped in some sort of state where it
can''t figure out a valid value for the primary key when the database
will overwrite it anyways.

Thanks for the pointers, though. Hopefully we''ll be using SQL Server
at some point in the future and then I''ll be able to escape from the
imperfect mapping of ADO.Net to Oracle.

Dave Sexton wrote:

Hi Martin,

Commonly, one would just set AutoIncrement, ReadOnly and Unique all to true on
the sequenced column.

I''m not an Oracle user, however, but I know this approach works with
auto-numbered columns in Sql Server. I can''t imagine it being different from
Oracle since the issue here is really dealing with how ADO.NET handles that
concept, regardless of the RDBMS.

--
Dave Sexton

"Martin Z" <ma***********@gmail.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...

I''m making a CRUD screen for an Oracle database... but problem is that
the primary key in that table is populated via an autonumber, which in
Oracle is done just with triggers and sequences. Suffice to say that
ADO.Net 1.1 is unaware that this column is, despite appearances,
optional - which is a problem when creating new rows. I was wondering
what the best way to remove the constraint is? I''ve been bitten too
many times by assuming the direct approach with ADO.Net - there are too
many hidden gotchas. My first instinct is to just set the datacolumn''s
AllowDBNull property - but the constraint still blows up on
GetChanges() - which I''m using to check if any real constraints are
being violated.

Any pointers?


Hi Martin,

>Commonly, one would just set AutoIncrement, ReadOnly and Unique all to true
on
the sequenced column.

I''m not an Oracle user, however, but I know this approach works with
auto-numbered columns in Sql Server. I can''t imagine it being different
from
Oracle since the issue here is really dealing with how ADO.NET handles that
concept, regardless of the RDBMS.


Just gave that a shot, with a few variations on the autoincrement
properties - it doesn''t seem to allow the constraint to be violated,

But that should be a good thing ;)

and it doesn''t seem to be sufficiently intelligent to determine
appropriate values for the insertion.

No, it doesn''t insert that value at all since it represents a sequenced column
that has a value generated by Oracle. It''s purpose in the DataTable is to
provide a unique key that serves as a placeholder until the data is inserted
into the database, in which case the DataRow should be updated with the
correct, Oracle-generated, value.

I think I''ll have to give up and use EnforceConstraints = false.

Eeek.

Better to get an error on database update that I can work with than
risk the application getting trapped in some sort of state where it
can''t figure out a valid value for the primary key when the database
will overwrite it anyways.

The database shouldn''t be overwriting anything since the value shouldn''t be
supplied to the database during an insert, because it has no meaning. The
value should, however, be updated in the DataRow from the data source itself
after the insert.

When you insert the record you should return a result set with the new
sequence value generated by Oracle:

-- T-SQL, but hopefully you''ll get the idea:

INSERT table SELECT @non_key_1, @non_key_2;

SELECT key, non_key_1, non_key_2 FROM table
WHERE key = SCOPE_IDENTITY();

The DbDataAdapter is supposed to handle the update of the underlying DataRow
automatically when the InsertCommand''s UpdatedRowSource property is set
appropriately (SqlCommand defaults to "Both").

I''m not sure if the OracleDataAdapter provides this functionality, but it''s
worth testing out. If Oracle doesn''t provide this capability then I''m not
sure what you can do.

Thanks for the pointers, though. Hopefully we''ll be using SQL Server
at some point in the future and then I''ll be able to escape from the
imperfect mapping of ADO.Net to Oracle.

NP, GL ;)

--
Dave Sexton


这篇关于在模式中覆盖AllowNull的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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