Search code examples
linqlambdaado.net-entity-data-model

Can't seem to intellisense an entity (entity data framework)


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!


Solution

  • 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);
    }