开发者

How to address "Can't decide which property to consider the Key" error

I'm getting this error message:

"Can't decide which property to consider the Key - you can create one called 'ID开发者_Go百科' 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?


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.


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜