views:

468

answers:

2

Hi!

I have four tables:

  • Client with PK ClientID.
  • Destination with PK DestinationID.
  • Language with PK LanguageID.
  • DestinationDetail with PK DestinationID.
  • RL-Client-Destination with PKs ClientID and DestinationID.

The Client may have zero or n Destinations. A destination has n DestinationDetails, each of these DestinationDetail has a language.

Ok. I need to retrieve all of DestinationDetails for a given client and a given language.

I wrote this (I don't kown if it works), but maybe there is a better way:


    ObjectQuery clientQuery =
       guiaContext.Client.Where("it.email = @email",
           new ObjectParameter("email", "[email protected]"));

    Client client = clientQuery.First();

    client.Destination.Load();
    EntityCollection destinations = client.Destination;

    ObjectQuery languageQuery =
       guiaContext.Language.Where("it.ds_language = @languageDS",
         new ObjectParameter("languageDS", "en-US"));
    Language language = languageQuery.First();

    foreach (Destination dest in destinations)
    {
        dest.DestinationDetail.Load();
        EntityCollection details = dest.DestinationDetail;
        foreach (DestinationDetail detail in details)
        {
           detail.Language = language;
           Console.WriteLine("Destination: " + detail.ds_destinationName);
        }
     }

I'm learning ADO.NET Entity Framework.

Thanks!

A: 

"it.ds_language = @languageDS"

You can use strings for predicates in Entity Framework?

leppie
It's only an example to show the name of entities.
VansFannel
A: 
VansFannel