Correct declaration of Index for String types?

Aug 19, 2011 at 5:10 PM

I cannot seem to get the definition of indexes for strings right. Any clues welcomed. The snippet below defines 2 indexes, the integer variety works fine but the string does not. At registration I get an InvalidCastException.

CreateTableDefinition<CompositeImageData,int>(uc => uc.Index)
						.WithIndex<CompositeImageData,int,int>(CompositeSequenceIndex,uc => uc.Sequence)
						.WithIndex<CompositeImageData,String,String>(CompositeUuidIndex,uc => uc.Uuid),

If I create the index as shown below, the compiler insists that the return type is an int, which seems right.
					CreateTableDefinition<CompositeImageData,int>(uc => uc.Index)
						.WithIndex<CompositeImageData,int,int>(CompositeSequenceIndex,uc => uc.Sequence)
						.WithIndex<CompositeImageData,String,int>(CompositeUuidIndex,uc => uc.Uuid),


Can anyone give me a clue?

Many thanks

Aug 19, 2011 at 5:38 PM

OK, the problem here is with my query. The variety of the index declaration is the correct one, i.e. <class type, String, int>

The issue to which I alluded with the compiler stems from this construct:

// N.B. imd.Uuid is a string. Here we check for prior existence.
// the correct form. Here we are using the index
if ((from index in Database.Query<CompositeImageData, String, int>(CompositeUuidIndex) 
   where index.Index == imd.Uuid select index.Key).Any())

// this form uses the primary key, which is an int, *NOT* the index
if ((from k in Database.Query<CompositeImageData, String, int>(CompositeUuidIndex) 
   where k.Key == imd.Uuid select index.Key).Any())

I hope this helps someone without an afternoon to spare .... :)


Aug 21, 2011 at 3:23 PM

Thanks for following up, Jerry!