abe545 / CodeOnlyStoredProcedures

A library for easily calling Stored Procedures in .NET using only code (no xml or gui).
MIT License
4 stars 3 forks source link

Can I use CodeOnlyStoredProcedures in database first approch to execute stored procedure? #88

Closed p-ideal closed 7 years ago

p-ideal commented 7 years ago

Can I use CodeOnlyStoredProcedures in database first approch to execute stored procedure? If yes then how can I do it.Please let me ASAP. Thanks in advance.

abe545 commented 7 years ago

Yes, in fact you don't need Entity Framework for this at all. All you need is the IDbConnection object, which you can easily construct from a connection string. For SQL Server, for instance, this is a SqlConnection. Here is how I generally create them:

IDbConnection connection = new SqlConnection(
    ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString);
p-ideal commented 7 years ago

Not Working in Mysql:

This is what I am doing

IDbConnection connection = context.Database.Connection;

connection.Execute().sp_dummy(id: inID);

Getting Exception: Procedure or function '[sp_dummy]' cannot be found in database '[xxx]'.

where xxx is my schema

I think it is using SQL Server syntax to fetch data from database such as [SchemaName][DatabaseName] and MySql does not use '[' or ']' brackets.

Let me know if you need any info from my side.

abe545 commented 7 years ago

@p-ideal this is the same bug as #87. I've added support, but messed up the way to expose set it. I should have this fixed tonight.

abe545 commented 7 years ago

@p-ideal, to call them in MySQL, before making any database calls, call the configuration method: StoredProcedure.SetObjectQuoteStyle(ObjectQuoteStyle.Backtick);

This will only work with 2.3.0-pre05 and up, however.