0

i wrote a stored procedure in SQL server Management Studio like this : enter image description here

Then I'm using it in a C# WPF Application with an Entity Framework DataModel :

public static void AdressagePalettesEntr(int stoId, string entite, string adresse)
    {
        using (GsDataModel dc = new GsDataModel())
        {
            int i = dc.WMSEntr_Adressage_Palettes(stoId: stoId,
                                                  entite: entite,
                                                  adresse: adresse);
            _ = dc.SaveChanges();
        }
    }

What i want is : when the stored procedure is at "print('Adresse indisponible !')" the user will see a messagebox with the appropriate text in it.

Thanks for helping me

Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
  • Not being versed in French I'm assuming you are merely wanting to save/update an entry in the database and with your C# code could produce the majority of the error message to display to the user. i.e. _"A problem occurred saving the address"_. It's kinda ironic because C# is better at handling multi-culture than a DB –  Mar 10 '22 at 03:35
  • search for `ef get stored procedure output` – Lei Yang Mar 10 '22 at 03:40
  • What's the point of `SaveChanges` ? That will persist *all pending object changes* to the database. It doesn't affect query execution. EF's DbContext isn't a data model either, it's a multi-entity Unit-of-Work/Repository. It's meant to contain the *entities* needed for specific use cases and map them to a database – Panagiotis Kanavos Mar 10 '22 at 07:41
  • The stored procedure makes little sense and can only *cause* problems. Transactions are used to protect changes, not SELECT. This stored procedure will do nothing at best (if there's no existing transaction), or roll back any pre-existing transactions at worst – Panagiotis Kanavos Mar 10 '22 at 07:42
  • What are you trying to do with this code? Whatever it is, there are better ways to do it. If you want to insert an entity only if it doesn't exist, it's better to just try and read its ID. The query will be the same but the returned data will be *smaller* than the *debug message* returned by this stored procedure. – Panagiotis Kanavos Mar 10 '22 at 07:46

0 Answers0