views:

69

answers:

1

Ok, this is an interesting problem I think

I have a list of items in a db, which have authors. (1 to 1 relationship, "authorId" is the foreign key).

I need to get a list of letters in the alphabet which have a user to match it (by Surname)

For instance, lets pretend there are only 3 items in the db. They were contributed by Mr Car, Mrs Jam and Dr Toffee.

The method would return an array of letters (C, J and T). Actually what would be more useful is a list of the whole alphabet and the C J and T items would have some kind of "active" boolean.

The reason for this is I will eventually have a web page of contributors which has a list of the letters in the alphabet, the user will be able to press on a letter and get a list of contributors. But I need to be able to only enable letters which have contributors. Just pulling from the list of users isnt good enough as some users wont have contributed anything.

I have a method which gets all contributors to start with:

    return from u in users.All()
           where items.All().Count(i => i.authorId == u.id) > 0
           select u;
+3  A: 

How about:

.select(u=>u.Surname.Substring(0,1)).Distinct()

You can then join this to a list of all letters in the alphabet fairly easily.

Mike.

MikeeMike