我正在创建一个实体图,我对Id上的StoreGeneratedPattern
属性有疑问。我有两个Identity
和Computed
选项,我不确定何时使用每个选项。我猜我应该在实体生成时使用Identity
,而在外键时使用Computed
,因为它是由另一个身份生成的。我是对的还是反过来的?谢谢!
答案 0 :(得分:1)
如果您只是查看官方 MSDN documentation for this property,您会看到:
$(document).ready(function ()
{
$('.delete').click(function ()
{
$('.confirm').toggleClass('confirmShow');
var clickBtnValue = $(this).val();
var ajaxurl = 'ajaxDelete.php',
data = {'action': clickBtnValue};
$.post(ajaxurl, data, function (response) {
});
if ($(this).val() == "Delete Account")
{
$(this).val("yes");
}
else if ($(this).val() == "yes")
{
$(this).val("Delete Account");
//When the below line is removed it works perfectly
window.location.href = 'Functions/LogOut.php';
}
else if ($(this).val() == "No")
{
$('#delete').val("Delete Account");
}
});
});
因此,如果您的PK列为Member name Description
-----------------------------------------------------------------------------
Computed A value is generated on both insert and update.
Identity A value is generated on insert and remains unchanged on update.
None A value indicating that it is not a server generated property.
,那么很明显 - 使用INT IDENTITY
值。
Identity
值应该用于数据库表中的计算列,通常在插入时计算并在更新时重新计算。这是 NOT 用于外键列!这些只是常规列 - 为 NOT 设置任何Computed
值!!