///<summary>
        /// Method Invocation of wrapper classes
        ///<summary>
        protected static FR_L5BL_GBIfBI_1159 Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L5BL_GBIfBI_1159 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            bool cleanupConnection  = Connection == null;
            bool cleanupTransaction = Transaction == null;

            FR_L5BL_GBIfBI_1159 functionReturn = new FR_L5BL_GBIfBI_1159();

            try
            {
                if (cleanupConnection == true)
                {
                    Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(ConnectionString);
                    Connection.Open();
                }
                if (cleanupTransaction == true)
                {
                    Transaction = Connection.BeginTransaction();
                }

                functionReturn = Execute(Connection, Transaction, Parameter, securityTicket);


                #region Cleanup Connection/Transaction
                //Commit the transaction
                if (cleanupTransaction == true)
                {
                    Transaction.Commit();
                }
                //Close the connection
                if (cleanupConnection == true)
                {
                    Connection.Close();
                }
                #endregion
            }
            catch (Exception ex)
            {
                try
                {
                    if (cleanupTransaction == true && Transaction != null)
                    {
                        Transaction.Rollback();
                    }
                }
                catch { }

                try
                {
                    if (cleanupConnection == true && Connection != null)
                    {
                        Connection.Close();
                    }
                }
                catch { }

                throw ex;
            }
            return(functionReturn);
        }
        protected static FR_L5BL_GBIfBI_1159 Execute(DbConnection Connection, DbTransaction Transaction, P_L5BL_GBIfBI_1159 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5BL_GBIfBI_1159();
            //Put your code here
            var building = new ORM_RES_BLD_Building();
            building.Load(Connection, Transaction, Parameter.BuildingID);
            if (building == null || building.RES_BLD_BuildingID == Guid.Empty)
            {
                return(null);
            }
            returnValue.Result = new L5BL_GBIfBI_1159();
            returnValue.Result.Building_BalconyPortionPercent        = building.Building_BalconyPortionPercent;
            returnValue.Result.Building_DocumentationStructure_RefID = building.Building_DocumentationStructure_RefID;
            returnValue.Result.Building_ElevatorCoveragePercent      = building.Building_ElevatorCoveragePercent;
            returnValue.Result.Building_Name = building.Building_Name;
            returnValue.Result.Building_NumberOfAppartments         = building.Building_NumberOfAppartments;
            returnValue.Result.Building_NumberOfOccupiedAppartments = building.Building_NumberOfOccupiedAppartments;
            returnValue.Result.Building_NumberOfFloors          = building.Building_NumberOfFloors;
            returnValue.Result.Building_NumberOfOffices         = building.Building_NumberOfOffices;
            returnValue.Result.Building_NumberOfOtherUnits      = building.Building_NumberOfOtherUnits;
            returnValue.Result.Building_NumberOfProductionUnits = building.Building_NumberOfProductionUnits;
            returnValue.Result.Building_NumberOfRetailUnits     = building.Building_NumberOfRetailUnits;
            returnValue.Result.BuildingRevisionHeader_RefID     = building.BuildingRevisionHeader_RefID;
            returnValue.Result.IsContaminationSuspected         = building.IsContaminationSuspected;
            returnValue.Result.RES_BLD_BuildingID = building.RES_BLD_BuildingID;
            ORM_RES_BLD_Building_2_BuildingType type = ORM_RES_BLD_Building_2_BuildingType.Query.Search(Connection, Transaction, new ORM_RES_BLD_Building_2_BuildingType.Query {
                RES_BLD_Building_RefID = building.RES_BLD_BuildingID, Tenant_RefID = securityTicket.TenantID, IsDeleted = false
            }).FirstOrDefault();
            if (type != null)
            {
                returnValue.Result.BuildingType_RefID = type.RES_BLD_Building_Type_RefID;
            }
            ORM_RES_BLD_Building_2_GarbageContainerType garbageType = ORM_RES_BLD_Building_2_GarbageContainerType.Query.Search(Connection, Transaction, new ORM_RES_BLD_Building_2_GarbageContainerType.Query {
                RES_BLD_Building_RefID = building.RES_BLD_BuildingID, Tenant_RefID = securityTicket.TenantID, IsDeleted = false
            }).FirstOrDefault();
            if (type != null)
            {
                returnValue.Result.GarbageContainerType_RefID = garbageType.RES_BLD_GarbageContainerType_RefID;
            }

            var apartments         = new List <L5BL_GBIfBI_1159_Apartment>();
            var basements          = new List <L5BL_GBIfBI_1159_Basement>();
            var attics             = new List <L5BL_GBIfBI_1159_Attic>();
            var outdoorFascilities = new List <L5BL_GBIfBI_1159_OutdoorFacility>();
            var facades            = new List <L5BL_GBIfBI_1159_Facade>();
            var HVACRs             = new List <L5BL_GBIfBI_1159_HVACR>();
            var staircases         = new List <L5BL_GBIfBI_1159_Staircase>();
            var roofs = new List <L5BL_GBIfBI_1159_Roof>();

            #region apartments
            var ormApartments = ORM_RES_BLD_Apartment.Query.Search(Connection, Transaction, new ORM_RES_BLD_Apartment.Query()
            {
                Tenant_RefID   = securityTicket.TenantID,
                IsDeleted      = false,
                Building_RefID = Parameter.BuildingID
            });

            foreach (var ormApartment in ormApartments)
            {
                var apt = new L5BL_GBIfBI_1159_Apartment()
                {
                    ApartmentSize_Unit_RefID    = ormApartment.ApartmentSize_Unit_RefID,
                    ApartmentSize_Value         = ormApartment.ApartmentSize_Value,
                    RES_BLD_ApartmentID         = ormApartment.RES_BLD_ApartmentID,
                    IsAppartment_ForRent        = ormApartment.IsAppartment_ForRent,
                    Appartment_HeatingType      = ormApartment.TypeOfHeating_RefID,
                    Appartment_FlooringType     = ormApartment.TypeOfFlooring_RefID,
                    Appartment_WallCoveringType = ormApartment.TypeOfWallCovering_RefID,
                    RES_BLD_Apartment_TypeID    = ORM_RES_BLD_Apartment_2_ApartmentType.Query.Search(Connection, Transaction, new ORM_RES_BLD_Apartment_2_ApartmentType.Query()
                    {
                        RES_BLD_Apartment_RefID = ormApartment.RES_BLD_ApartmentID,
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID
                    }).Select(a => a.RES_BLD_Apartment_Type_RefID).FirstOrDefault()
                };

                apartments.Add(apt);
            }
            #endregion


            #region attics
            var ormAttics = ORM_RES_BLD_Attic.Query.Search(Connection, Transaction, new ORM_RES_BLD_Attic.Query()
            {
                Tenant_RefID   = securityTicket.TenantID,
                IsDeleted      = false,
                Building_RefID = Parameter.BuildingID
            });

            foreach (var ormAttic in ormAttics)
            {
                var attic = new L5BL_GBIfBI_1159_Attic()
                {
                    RES_BLD_AtticID      = ormAttic.RES_BLD_AtticID,
                    RES_BLD_Attic_TypeID = ORM_RES_BLD_Attic_2_AtticType.Query.Search(Connection, Transaction, new ORM_RES_BLD_Attic_2_AtticType.Query()
                    {
                        RES_BLD_Attic_RefID = ormAttic.RES_BLD_AtticID,
                        IsDeleted           = false,
                        Tenant_RefID        = securityTicket.TenantID
                    }).Select(a => a.RES_BLD_Attic_Type_RefID).FirstOrDefault()
                };

                attics.Add(attic);
            }
            #endregion


            #region roofs
            var ormRoofs = ORM_RES_BLD_Roof.Query.Search(Connection, Transaction, new ORM_RES_BLD_Roof.Query()
            {
                Tenant_RefID   = securityTicket.TenantID,
                IsDeleted      = false,
                Building_RefID = Parameter.BuildingID
            });

            foreach (var ormRoof in ormRoofs)
            {
                var roof = new L5BL_GBIfBI_1159_Roof()
                {
                    RES_BLD_RoofID     = ormRoof.RES_BLD_RoofID,
                    RES_BLD_RoofTypeID = ORM_RES_BLD_Roof_2_RoofType.Query.Search(Connection, Transaction, new ORM_RES_BLD_Roof_2_RoofType.Query()
                    {
                        RES_BLD_Roof_RefID = ormRoof.RES_BLD_RoofID,
                        IsDeleted          = false,
                        Tenant_RefID       = securityTicket.TenantID
                    }).Select(r => r.RES_BLD_Roof_Type_RefID).FirstOrDefault()
                };

                roofs.Add(roof);
            }
            #endregion


            #region staircases
            var ormStaircases = ORM_RES_BLD_Staircase.Query.Search(Connection, Transaction, new ORM_RES_BLD_Staircase.Query()
            {
                Tenant_RefID   = securityTicket.TenantID,
                IsDeleted      = false,
                Building_RefID = Parameter.BuildingID
            });

            foreach (var ormStaircase in ormStaircases)
            {
                var staircase = new L5BL_GBIfBI_1159_Staircase()
                {
                    StaircaseSize_Unit_RefID = ormStaircase.StaircaseSize_Unit_RefID,
                    StaircaseSize_Value      = ormStaircase.StaircaseSize_Value,
                    RES_BLD_StaircaseID      = ormStaircase.RES_BLD_StaircaseID,
                    RES_BLD_Staircase_TypeID = ORM_RES_BLD_Staircase_2_StaircaseType.Query.Search(Connection, Transaction, new ORM_RES_BLD_Staircase_2_StaircaseType.Query()
                    {
                        RES_BLD_Staircase_RefID = ormStaircase.RES_BLD_StaircaseID,
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID
                    }).Select(s => s.RES_BLD_Staircase_Type_RefID).FirstOrDefault()
                };

                staircases.Add(staircase);
            }
            #endregion


            #region basements
            var ormBasements = ORM_RES_BLD_Basement.Query.Search(Connection, Transaction, new ORM_RES_BLD_Basement.Query()
            {
                Tenant_RefID   = securityTicket.TenantID,
                IsDeleted      = false,
                Building_RefID = Parameter.BuildingID
            });

            foreach (var ormBasement in ormBasements)
            {
                var basement = new L5BL_GBIfBI_1159_Basement()
                {
                    RES_BLD_BasementID      = ormBasement.RES_BLD_BasementID,
                    Basement_FloorType      = ormBasement.TypeOfFloor_RefID,
                    RES_BLD_Basement_TypeID = ORM_RES_BLD_Basement_2_BasementType.Query.Search(Connection, Transaction, new ORM_RES_BLD_Basement_2_BasementType.Query()
                    {
                        RES_BLD_Basement_RefID = ormBasement.RES_BLD_BasementID,
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID
                    }).Select(b => b.RES_BLD_Basement_Type_RefID).FirstOrDefault()
                };

                basements.Add(basement);
            }
            #endregion


            #region HVACRs
            var ormHVACRs = ORM_RES_BLD_HVACR.Query.Search(Connection, Transaction, new ORM_RES_BLD_HVACR.Query()
            {
                Tenant_RefID   = securityTicket.TenantID,
                IsDeleted      = false,
                Building_RefID = Parameter.BuildingID
            });

            foreach (var ormHVACR in ormHVACRs)
            {
                var hvacr = new L5BL_GBIfBI_1159_HVACR()
                {
                    RES_BLD_HVACRID      = ormHVACR.RES_BLD_HVACRID,
                    RES_BLD_HVACR_TypeID = ORM_RES_BLD_HVACR_2_HVACR_Type.Query.Search(Connection, Transaction, new ORM_RES_BLD_HVACR_2_HVACR_Type.Query()
                    {
                        RES_BLD_HVACR_RefID = ormHVACR.RES_BLD_HVACRID,
                        IsDeleted           = false,
                        Tenant_RefID        = securityTicket.TenantID
                    }).Select(h => h.RES_BLD_HVACR_Type_RefID).FirstOrDefault()
                };

                HVACRs.Add(hvacr);
            }
            #endregion


            #region facades
            var ormFacades = ORM_RES_BLD_Facade.Query.Search(Connection, Transaction, new ORM_RES_BLD_Facade.Query()
            {
                Tenant_RefID   = securityTicket.TenantID,
                IsDeleted      = false,
                Building_RefID = Parameter.BuildingID
            });

            foreach (var ormFacade in ormFacades)
            {
                var facade = new L5BL_GBIfBI_1159_Facade()
                {
                    RES_BLD_FacadeID      = ormFacade.RES_BLD_FacadeID,
                    RES_BLD_Facade_TypeID = ORM_RES_BLD_Facade_2_FacadeType.Query.Search(Connection, Transaction, new ORM_RES_BLD_Facade_2_FacadeType.Query()
                    {
                        RES_BLD_Facade_RefID = ormFacade.RES_BLD_FacadeID,
                        IsDeleted            = false,
                        Tenant_RefID         = securityTicket.TenantID
                    }).Select(f => f.RES_BLD_Facade_Type_RefID).FirstOrDefault()
                };

                facades.Add(facade);
            }
            #endregion



            #region outdoorFascilitys
            var ormOutdoorFascilitys = ORM_RES_BLD_OutdoorFacility.Query.Search(Connection, Transaction, new ORM_RES_BLD_OutdoorFacility.Query()
            {
                Tenant_RefID   = securityTicket.TenantID,
                IsDeleted      = false,
                Building_RefID = Parameter.BuildingID
            });

            foreach (var ormOutdoorFascility in ormOutdoorFascilitys)
            {
                var outdoorFascility = new L5BL_GBIfBI_1159_OutdoorFacility()
                {
                    RES_BLD_OutdoorFacilityID      = ormOutdoorFascility.RES_BLD_OutdoorFacilityID,
                    NumberOfGaragePlaces           = ormOutdoorFascility.NumberOfGaragePlaces,
                    NumberOfRentedGaragePlaces     = ormOutdoorFascility.NumberOfRentedGaragePlaces,
                    OutdoorFacility_AccessRoadType = ormOutdoorFascility.TypeOfAccessRoad_RefID,
                    OutdoorFacility_FenceType      = ormOutdoorFascility.TypeOfFence_RefID,
                    RES_BLD_OutdoorFacility_TypeID = ORM_RES_BLD_OutdoorFacility_2_OutdoorFacilityType.Query.Search(Connection, Transaction, new ORM_RES_BLD_OutdoorFacility_2_OutdoorFacilityType.Query()
                    {
                        RES_BLD_OutdoorFacility_RefID = ormOutdoorFascility.RES_BLD_OutdoorFacilityID,
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID
                    }).Select(o => o.RES_BLD_OutdoorFacility_Type_RefID).FirstOrDefault()
                };

                outdoorFascilities.Add(outdoorFascility);
            }
            #endregion

            returnValue.Result.Apartment       = apartments.ToArray();
            returnValue.Result.Attic           = attics.ToArray();
            returnValue.Result.Basement        = basements.ToArray();
            returnValue.Result.OutdoorFacility = outdoorFascilities.ToArray();
            returnValue.Result.Facade          = facades.ToArray();
            returnValue.Result.HVACR           = HVACRs.ToArray();
            returnValue.Result.Staircase       = staircases.ToArray();
            returnValue.Result.Roof            = roofs.ToArray();
            return(returnValue);

            #endregion UserCode
        }