1

My code is as follows:

var contactGroups = context.ContactGroups.Where(cg => cg.ContactID == contact.ID);

var MyContactGroups = from cg in context.ContactGroups
     where cg.Contact == contact.ID
     select new {
     Title = cg.Title,
      GroupName = cg.GroupName 
     };

The result of contactgroups and MyContactGroups doesn't allow me to access any of the records of ContactGroups..

i.e. When I use MyContactGroups I cannot access any of the columns such as GroupName or Title. For example, I can't use MyContactGroups.Title

I have posted the video of my issue here: http://screencast.com/t/i0ydKQSou

Any ideas what I am doing wrong please? Thanks!

PKCS12
  • 407
  • 15
  • 41

1 Answers1

2

MyContactGroups is going to be an IEnumerable<ContactGroup>. You'll need to get an individual item off of it to access the properties of a ContactGroup.

foreach(var contactGroup in MyContactGroups)
{
    Console.WriteLine(contactGroup.Title);
}
StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315