Subsonic : Can’t decide which property to consider the Key? foreign key issue.

Posted by AJ on Stack Overflow See other posts from Stack Overflow or by AJ
Published on 2009-11-30T22:57:33Z Indexed on 2010/05/20 20:20 UTC
Read the original article Hit count: 942

Hi

I am trying to select count of rows from a table which has foreign keys of two tables. The C# code threw the error mentioned below. So, I added a primary key column to the table (schema as follows) and regenerated the code. But still the same error is coming.

Error : Can't decide which property to consider the Key - you can create one called 'ID' or mark one with SubSonicPrimaryKey attribute

sqLite Table schema

CREATE TABLE "AlbumDocuments" ("Id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , "AlbumId" INTEGER NOT NULL CONSTRAINT  fk_AlbumId REFERENCES Albums(Id) ,
"DocumentId" INTEGER NOT NULL CONSTRAINT  fk_DocumentId REFERENCES Documents(Id))

C# code

int selectAlbumDocumentsCount = new SubSonic.Query.Select()
.From<DocSafeDB.DataLayer.AlbumDocumentsTable>()
    .Where(DocSafeDB.DataLayer.AlbumDocumentsTable.AlbumIdColumn).In(request.AlbumId)
    .Execute();

Not sure what I should be doing next as I can't do where against primary key because I don;t have that info. So my questions are:

  1. How do I select count of rows against foreign key column?

  2. Is primary key required in this scenario?

I have several things but not sure why its not working. To me it looks like a very normal use case. Please advise.

Thanks AJ

© Stack Overflow or respective owner

Related posts about subsonic

Related posts about templates