Simple Query Example

Apr 17, 2011 at 11:47 PM
Edited Apr 17, 2011 at 11:48 PM

I'm looking for an example of a simple query on 2 index fields. The documentation examples go from a basic key query to a complex join and I'm looking for something in the middle.

I have a class with a key field and 2 index fields. Here is the table definition:

    CreateTableDefinition<GridDetailDto, int>( k => k.RowId )
        .WithIndex<GridDetailDto, intint>("MasterId", t => t.GridMasterId)
        .WithIndex<GridDetailDto, intint>("JobId", t => t.JobId)

To get a list of keys my SQL query would be:

select RowId from GridDetailDto where GridMasterId = 1 and JobId = 2

How would I do this using sterling?




Apr 18, 2011 at 3:33 AM

Figured it out. Use a tuple for the composite index. Here is my code:

CreateTableDefinition<GridDetailDto, int>( k => k.GridDetailId)
.WithIndex<GridDetailDto, int, int, int>(GRID_DETAIL_MASTER_JOB_INDEX, t => Tuple.Create(t.GridMasterId, t.JobId)

List<GridDetailDto> gridDetailList = 
(from index in DatabaseInstance.Query<GridDetailDto, int, int, int>(KernDB.GRID_DETAIL_MASTER_JOB_INDEX) 
where index.Index.Item1 == gridMasterId 
where index.Index.Item2 == jobId 
select index.LazyValue.Value).ToList();