2

我有四张桌子:

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

客户端可能有零个或 n 个目的地。一个目的地有 n 个 DestinationDetails,每个 DestinationDetail 都有一种语言。

行。我需要检索给定客户端和给定语言的所有 DestinationDetails。

我开始写这个:

try
   {
      ObjectQuery clientes = 
          guiaContext.Cliente;
      ObjectQuery destinos =
          guiaContext.Destino;
      ObjectQuery idiomas =
          guiaContext.Idioma;
      ObjectQuery detalles =
          guiaContext.DetalleDestino;

      IQueryable detalleQuery =
          from cliente in clientes
          from destino in destinos
          from idioma in idiomas
          from detalleDestino in detalles
          where destino.
          select detalleDestino;

   }
   catch
   {
   }
}

有什么建议吗?

谢谢!

4

3 回答 3

2

它沿着这条线:

var detalleQuery =
          from client in guiaContext.Clients
          where client.ID == 1
          from destination in cliente.Destinations
          from destinationDetail in destination.DestionationDetails
          where destinationDetail.Language.Iso2Code == "es"
          select destinationDetail;
于 2009-03-21T07:38:24.377 回答
1

您是否尝试过进行 linq 连接:

使用 LINQ 从多个表中选择

于 2009-03-21T07:05:50.163 回答
0

我的答案:


var db = new PracticeEntities();
            var destinations = db.DestinationDetails.
                Where(dd => dd.Language.Lang == "en-US" &&
                dd.Destination.Client.Any(c => c.Email == "abc@yahoo.com"));


谢谢!

于 2009-03-21T09:13:56.580 回答