private EPassportAgent GetRight(DataUnitCustomer unifiedCustomer, SevRGas2EPassportCustomerMatchGuess matchGuess, EPassportAgent matchGuessObject)
 {
     return(matchGuessObject);
 }
        public void MainTest()
        {
            Require.AllFeaturesSupported(ProviderFeatures.ScalarSubqueries);
            using (var session = Domain.OpenSession()) {
                using (var transactionn = session.OpenTransaction()) {
                    var sevRGasCustomer2 = new SevRGasCustomer()
                    {
                        Code     = "Code",
                        FullName = "Customer FullName",
                        Name     = "Customer Name",
                        Tin      = 44
                    };
                    // var ePassportAgent2 = new EPassportAgent();
                    var sevRGas2EPassportCustomerMatchGuess2 = new SevRGas2EPassportCustomerMatchGuess {
                        SevRGasCustomerID   = sevRGasCustomer2.Id,
                        EPassportCustomerID = 12345,
                        Rank = 12345
                    };
                    var dataUnitCustomer2 = new DataUnitCustomer {
                        SevRGasCustomer = sevRGasCustomer2,
                        EPassportAgent  = null
                    };

                    var sevRGasCustomer1 = new SevRGasCustomer()
                    {
                        Code     = "Code",
                        FullName = "Customer FullName",
                        Name     = "Customer Name",
                        Tin      = 12
                    };
                    var ePassportAgent1 = new EPassportAgent();
                    var sevRGas2EPassportCustomerMatchGuess1 = new SevRGas2EPassportCustomerMatchGuess {
                        SevRGasCustomerID   = sevRGasCustomer1.Id,
                        EPassportCustomerID = ePassportAgent1.Id,
                        Rank = 12345
                    };
                    var dataUnitCustomer1 = new DataUnitCustomer {
                        SevRGasCustomer = sevRGasCustomer1,
                        EPassportAgent  = ePassportAgent1
                    };

                    var query =
                        from customer in session.Query.All <SevRGasCustomer>()
                        let matchGuess = session.Query.All <SevRGas2EPassportCustomerMatchGuess>().Where(
                            g => g.SevRGasCustomerID == customer.Id).FirstOrDefault()
                                         let matchGuessObject = session.Query.All <EPassportAgent>().Where(
                            go => go.Id == matchGuess.EPassportCustomerID).FirstOrDefault()
                                                                let unifiedCustomer = session.Query.All <DataUnitCustomer>().Where(
                            ua => ua.SevRGasCustomer == customer && ua.EPassportAgent != null).FirstOrDefault()
                                                                                      select new SevRGas2EPassportCustomerMatchListItem {
                        LeftID   = customer.Id,
                        LeftName = customer.Name ?? customer.FullName,
                        LeftUniqueTaxpayerNumber = customer.Tin,
                        LeftCode = customer.Code,
                        Rank     = matchGuess.Rank,
                        Status   = unifiedCustomer == null ? MatchStatus.NotConfirmed : MatchStatus.Confirmed,
                        Right    = GetRight(unifiedCustomer, matchGuess, matchGuessObject)
                    };
                    var result = query.ToList();
                }
            }
        }