如何解决“无法决定考虑哪个属性的密钥”问题错误

发布于 2024-09-27 06:44:42 字数 774 浏览 0 评论 0原文

我收到此错误消息:

“无法决定考虑哪个属性作为密钥 - 您可以创建一个名为“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌化 2024-10-04 06:44:42

您应该发布异常的堆栈跟踪。

这只是一个疯狂的猜测,但我认为 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 called ID.

天气好吗我好吗 2024-10-04 06:44:42

我的猜测是您的问题与 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文