如何解决“无法决定考虑哪个属性的密钥”问题错误
我收到此错误消息:
“无法决定考虑哪个属性作为密钥 - 您可以创建一个名为“ID”的属性或使用 SubSonicPrimaryKey 属性标记一个属性”
有问题的代码由 context.tt
生成:
public SqlQuery Delete<T>(Expression<Func<T,bool>> column) where T:new()
{
LambdaExpression lamda = column;
SqlQuery result = new Delete<T>(this.Provider);
result = result.From<T>();
result.Constraints=lamda.ParseConstraints().ToList();
return result;
}
在我的数据库中相应的表实际上有一个名为ID
的主键。我尝试插入 SubSonicPrimaryKey
属性:
uint _ID;
[SubSonicPrimaryKey]
public uint ID
{
get { return _ID; }
set
{...
如何解决此问题?
I'm getting this error message:
"Can't decide which property to consider the Key - you can create one called 'ID' or mark one with SubSonicPrimaryKey attribute"
The code in question is generated by the context.tt
:
public SqlQuery Delete<T>(Expression<Func<T,bool>> column) where T:new()
{
LambdaExpression lamda = column;
SqlQuery result = new Delete<T>(this.Provider);
result = result.From<T>();
result.Constraints=lamda.ParseConstraints().ToList();
return result;
}
In my DB the respective table actually has a primary key called ID
. And I tried to insert the SubSonicPrimaryKey
Attribute:
uint _ID;
[SubSonicPrimaryKey]
public uint ID
{
get { return _ID; }
set
{...
How can I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该发布异常的堆栈跟踪。
这只是一个疯狂的猜测,但我认为 subsonic 找到了两个可能的主键,一个称为 ID,另一个具有
SubSonicPrimaryKey
属性,并且不检查它们是否相等,因为可能的键的数量是不等于1则抛出异常。您应该尝试删除类的
SubSonicPrimaryKey
属性,因为该属性已被称为ID
。You should post the stack trace of your exception.
This is just a wild guess but I suppose subsonic finds two possible primary keys, the one called ID and one with the
SubSonicPrimaryKey
attribute and does not check wether they are equal and since the count of the possible keys is not equal to 1 the exception is thrown.You should try to remove the
SubSonicPrimaryKey
attribute of your class, since the Property is already calledID
.我的猜测是您的问题与 uint 值类型有关。 SubSonic 在处理无符号值类型时存在问题。
尝试使用 int 属性代替主键!
My guess is that your issue is related to the uint value type. SubSonic has is problems handling unsigned value types.
Try using a int property instead for your primary key!