views:

34

answers:

1

I'm having to downgrade a site from .NET 4 beta 2 to .NET 3.5.

The biggest hurdle is all the foreign key identity values I reference/lookup, as this isn't supported natively in EF 3.5.

Does anyone know of a reasonable work-around for this?

An example of what I mean is:

contacts.Where(contact => contact.TypeGuid == guid)

[TypeGuid] is a FK to [ContactTypes], so I get a [ContactType] object that I can access if I use .Include("ContactType"), but not the direct ID itself.

+1  A: 

Your sample query "just works" in EF 1 if you specify the ID property:

var someContact = Context.Contacts.Where(c => c.ContactType.Id == guid);

This is in LINQ to Entities.

In object space, you can refer to the EntityKey:

var someContact = contacts.Where(c => { var ek = c.ContactTypeReference.EntityKey;
                                        if (ek == null) return false;
                                        return ek.EntityKeyValues[0].Value.Equals(guid);
                                       });
Craig Stuntz