简体   繁体   中英

Stored procedure mapping using EF6 and Mysql database

I have ac# application using Entity framework 6 and Mysql Database . I added this stored procedure:

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `ps_reservation`(IN id_compte varchar(128))
BEGIN
    if id_compte is null then
        SELECT
            `ajtdev`.`ajt_demande`.`id` AS `id_demande`,
            `ajtdev`.`ajt_demande`.`date_intervention` AS `date_intervention`,
            `ajtdev`.`ajt_demande`.`from_time` AS `from_time`,
            `ajtdev`.`ajt_demande`.`to_time` AS `to_time`,
            `ajtdev`.`ajt_demande`.`id_begin_place` AS `id_from_place`,
            `ajtdev`.`ajt_demande`.`id_end_place` AS `id_to_place`,
            `ajtdev`.`ajt_demande`.`bot` AS `bot`,
            `ajtdev`.`ajt_client`.`nom` AS `nom_client`,
            `ajtdev`.`ajt_client`.`prenom` AS `prenom_client`,
            `ajtdev`.`ajt_coordonne`.`tel` AS `tel_client`,
            `ajtdev`.`ajt_statut_demande`.`libelle` AS `statut_demande`,
            `ajtdev`.`ajt_vehicle`.`immarticulation` AS `immarticulation_vehicle`,
            `ajtdev`.`ajt_vehicle`.`marque` AS `marque_vehicle`,
            `ajtdev`.`ajt_collaborator`.`id` AS `id_chauffeur`,
            `ajtdev`.`ajt_collaborator`.`Nom` AS `nom_chauffeur`,
            `ajtdev`.`ajt_collaborator`.`Prenom` AS `prenom_chauffeur`,
            `ajtdev`.`ajt_collaborator`.`id_user_fk` AS `id_user`
        FROM
           `ajtdev`.`ajt_demande` JOIN `ajtdev`.`ajt_statut_demande` ON (`ajtdev`.`ajt_demande`.`id_statut` = `ajtdev`.`ajt_statut_demande`.`id`)
            JOIN `ajtdev`.`ajt_client` ON (`ajtdev`.`ajt_demande`.`id_client` = `ajtdev`.`ajt_client`.`id`)
            JOIN `ajtdev`.`ajt_coordonne` ON (`ajtdev`.`ajt_client`.`id_coordonne` = `ajtdev`.`ajt_coordonne`.`id`)
           JOIN `ajtdev`.`ajt_ass_veh_col` ON (`ajtdev`.`ajt_demande`.`id_ass_veh_col_fk` = `ajtdev`.`ajt_ass_veh_col`.`id`)
           JOIN `ajtdev`.`ajt_vehicle` ON ( `ajtdev`.`ajt_ass_veh_col`.`veh_id_fk`  = `ajtdev`.`ajt_vehicle`.`Id`)
           JOIN `ajtdev`.`ajt_collaborator` ON (`ajtdev`.`ajt_ass_veh_col`.`col_id_fk` = `ajtdev`.`ajt_collaborator`.`Id`)
        WHERE
            ISNULL(`ajtdev`.`ajt_demande`.`deletion_date`)
            and ISNULL(`ajtdev`.`ajt_collaborator`.`deletion_date`)
            and ISNULL(`ajtdev`.`ajt_client`.`deletion_date`)
            and ISNULL(`ajtdev`.`ajt_vehicle`.`deletion_date`);
    else
        SELECT
            `ajtdev`.`ajt_demande`.`id` AS `id_demande`,
            `ajtdev`.`ajt_demande`.`date_intervention` AS `date_intervention`,
            `ajtdev`.`ajt_demande`.`from_time` AS `from_time`,
            `ajtdev`.`ajt_demande`.`to_time` AS `to_time`,
            `ajtdev`.`ajt_demande`.`id_begin_place` AS `id_from_place`,
            `ajtdev`.`ajt_demande`.`id_end_place` AS `id_to_place`,
            `ajtdev`.`ajt_demande`.`bot` AS `bot`,
            `ajtdev`.`ajt_client`.`nom` AS `nom_client`,
            `ajtdev`.`ajt_client`.`prenom` AS `prenom_client`,
            `ajtdev`.`ajt_coordonne`.`tel` AS `tel_client`,
            `ajtdev`.`ajt_statut_demande`.`libelle` AS `statut_demande`,
            `ajtdev`.`ajt_vehicle`.`immarticulation` AS `immarticulation_vehicle`,
            `ajtdev`.`ajt_vehicle`.`marque` AS `marque_vehicle`,
            `ajtdev`.`ajt_collaborator`.`id` AS `id_chauffeur`,
            `ajtdev`.`ajt_collaborator`.`Nom` AS `nom_chauffeur`,
            `ajtdev`.`ajt_collaborator`.`Prenom` AS `prenom_chauffeur`,
            `ajtdev`.`ajt_collaborator`.`id_user_fk` AS `id_user`
        FROM
           `ajtdev`.`ajt_demande` JOIN `ajtdev`.`ajt_statut_demande` ON (`ajtdev`.`ajt_demande`.`id_statut` = `ajtdev`.`ajt_statut_demande`.`id`)
            JOIN `ajtdev`.`ajt_client` ON (`ajtdev`.`ajt_demande`.`id_client` = `ajtdev`.`ajt_client`.`id`)
            JOIN `ajtdev`.`ajt_coordonne` ON (`ajtdev`.`ajt_client`.`id_coordonne` = `ajtdev`.`ajt_coordonne`.`id`)
           JOIN `ajtdev`.`ajt_ass_veh_col` ON (`ajtdev`.`ajt_demande`.`id_ass_veh_col_fk` = `ajtdev`.`ajt_ass_veh_col`.`id`)
           JOIN `ajtdev`.`ajt_vehicle` ON ( `ajtdev`.`ajt_ass_veh_col`.`veh_id_fk`  = `ajtdev`.`ajt_vehicle`.`Id`)
           JOIN `ajtdev`.`ajt_collaborator` ON (`ajtdev`.`ajt_ass_veh_col`.`col_id_fk` = `ajtdev`.`ajt_collaborator`.`Id`)
        WHERE
            ISNULL(`ajtdev`.`ajt_demande`.`deletion_date`)
            and ISNULL(`ajtdev`.`ajt_collaborator`.`deletion_date`)
            and ISNULL(`ajtdev`.`ajt_client`.`deletion_date`)
            and ISNULL(`ajtdev`.`ajt_vehicle`.`deletion_date`)
            and CONVERT(`ajtdev`.`ajt_collaborator`.`id_user_fk` USING UTF8)= id_compte;
    end if;

END$$
DELIMITER ;

When I added a new EF model, in the context I get this mappage:

 public virtual int ps_reservation(string id_compte)
{
    var id_compteParameter = id_compte != null ?
        new ObjectParameter("id_compte", id_compte) :
        new ObjectParameter("id_compte", typeof(string));

    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("ps_reservation", id_compteParameter);
}

I don't understand Why I get this method signature:

public virtual int ps_reservation(string id_compte)

I mean why the return type is integer !! Why it is not ObjectResult<ps_reservation_Result> ?

  1. What are the reasons of this error?
  2. How can I fix it?

After Researching

I found the solution here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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