Subsonic 3.0.0.3 getting distinct items on column name. ActiveRecord

297 Views Asked by At

I have the following structure for a table

CREATE TABLE [dbo].[CityDistancesMin](
    [Id] int identity(1,1) not null,
    [City1] [int] NOT NULL,
    [City2] [int] NOT NULL,
    [Car] [nvarchar](50) NOT NULL,
    [Distance] [int] NOT NULL,
CONSTRAINT [PK_CityDistancesMin] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF,
    ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) 
ON [PRIMARY]

And I need a way to get different Ids of the cities in SubSonic 3.0.0.3 . For example, on sql it would only be a Select distinct City1 from CityDistancesMin

I was trying to do the following

SqlQuery query = new Select(CityDistancesMinTable.City1Column)
    .From< CityDistancesMinTable>();
     query.Aggregates = new List<Aggregate> {
          new Aggregate(CityDistancesMinTable.City1Column, AggregateFunction.GroupBy)
     };

But I'm getting the following error:

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

I've tried renaming Id to ID but it doesn't seems to help.

1

There are 1 best solutions below

0
On

It's not obvious how you managed to trigger this error from that database. The error is line 301 in file Extensions.Object.cs, and should be related to analysing a schema based on property attributes in code. If you are using the ActiveRecord templates to process your database schema it should have found the ID column, but in any case should not trigger this error. At least that's how I understand it.

If this doesn't help, can you try posting a repro case? Absolute minimum lines of code to reproduce this error with that database.