-2

I have a table with Guid column as primary key.

enter image description here

How can I get the row index of a column using entity framework. For example I want to get the row index of Grapes

Ramppy Dumppy
  • 2,667
  • 7
  • 27
  • 37
  • possible duplicate of [Get Row Index in a list by using entity framework](http://stackoverflow.com/questions/20259737/get-row-index-in-a-list-by-using-entity-framework) – Jaycee May 12 '14 at 10:13
  • And you have accounted for a GUID being a poor choice for a primary key? – Jaycee May 12 '14 at 10:14
  • @Jaycee GUID as primary key is not a poor choice.. see this article http://blog.codinghorror.com/primary-keys-ids-versus-guids/ – Ramppy Dumppy May 12 '14 at 10:24
  • I would do a bit more research if I were you, try this http://stackoverflow.com/questions/897083/when-would-you-use-guids-as-primary-keys/897112#897112 Perhaps the GUIDs fit your scenario who knows – Jaycee May 12 '14 at 11:45

1 Answers1

0

You can get the index of the element directly if your list has implemented indexer.

In your case, for example if you want the Grapes index you can do this (I do not recommend using it in tables with many elements because from the point of view of the performance ToList() is bad):

Table test= Table.Where<Table>( x => return x.Name== "Grapes";).Single<Table>();
int index = Table.ToList().IndexOf(test);
faby
  • 7,394
  • 3
  • 27
  • 44