简体   繁体   English

查询-数据集中的完全外部联接2个不同的表-LINQ C#

[英]Query - Full outer join 2 different tables in a Dataset - LINQ C#

I want to make a join from two different tables (with no connection between them): 我想从两个不同的表进行联接(它们之间没有连接):

Parkinglot (parkingLotID, addressParkingLot, statusParkingLot) 停车场 (parkingLotID,addressParkingLot,statusParkingLot)

PublicParking (publicParkingID, addressPublicParking, statusParking). PublicParking (publicParkingID,地址PublicParking,statusParking)。

And I want to write a query that returns all the parking that is available - based on their status (Parking lot & PublicParking). 我想写一个查询,根据其状态(停车场和PublicParking)返回所有可用的停车场。

I've read that I need to do full outer join (make one big table) and only then I can write the query. 我读过我需要做完整的外部联接(创建一个大表),只有这样我才能编写查询。

I need to write the query in LINQ. 我需要在LINQ中编写查询。

I really need your help about this query and about the full outer join (if it's right) 我真的需要您提供有关此查询和完整外部联接的帮助(如果正确的话)

using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {

        IList<parkingLot> parkingLot=new List <parkingLot>(){

        new parkingLot {parkingLotID=1, addressParkingLot="bograshov 22",statusParkingLot=true},
        new parkingLot {parkingLotID=2, addressParkingLot="bograshov 10",statusParkingLot=false},
        new parkingLot {parkingLotID=3, addressParkingLot="bograshov 28",statusParkingLot=true},
    };



    IList<publicParking> PublicParking=new List <publicParking>(){

        new publicParking {publicParkingID=101, addressPublicParking= "bograshov 23",statusParking=true},
        new publicParking {publicParkingID=102, addressPublicParking= "bograshov 21",statusParking=true},
        new publicParking {publicParkingID=103, addressPublicParking= "bograshov 18",statusParking=false},
    };


  (from lot in parkingLot
    where lot.statusParkingLot == true
    select lot).Union(from pub in PublicParking
    where pub.statusParking==true
    select pub);


   }
}

public class publicParking 
{
 public int publicParkingID { get; set; }
 public string addressPublicParking { get; set; }
    public bool statusParking { get; set; }

}


public class parkingLot 
{
  public int parkingLotID { get; set; }
  public string addressParkingLot { get; set; }
  public bool statusParkingLot { get; set; }

 }

TNX! TNX!

UPDATE UPDATE

I wrote the query but its have a problem: 我写了查询,但是有一个问题:

New problem 新问题

You can use Union for joining two tables without having common fields. 您可以使用Union来联接两个表而无需公共字段。 LINQ query for your scenario will look something like this. 您的方案的LINQ查询将如下所示。

 (from lot in ParkingLots
 where lot.StatusParkingLot == true
 select lot).Union( from pub in PublicParkings
 where pub.StatusParking==true
 select pub);

Hope this works! 希望这有效!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM