Best method for using stored procedures and table valued functions in ASP.NET Core 5 - asp.net-core

We are developing a razor application with VueJS on the frontend and razor / ASP.NET Core 5 on the backend. VueJS accesses the data via post (ajax) requests which we are handling using page handlers in the page models.
I have integrated Entity Framework and done a few queries for practice however I am realizing Entity Framework is not my answer. All of my SQL queries are saved as table valued functions in SQL Server and the update / insert / delete operations are done using stored procedures in SQL Server.
We have a SQL programmer so he just does everything server-side to keep things simple and just gives us function / procedure names and parameters.
I like this approach and we used this in our application when it was VBA in Excel using ADO and recordsets but now that we are using ASP.NET Core in a web setting so I am learning Entity Framework. However EF requires me to maintain models and that seems unnecessarily complicated as my SQL results are generated from procedures / functions.
Really I just need to run these procedures / functions and return the results as a json data array in the POST request.
What would be the best option for this in regards to performance and simplicity (hopefully they can go hand in hand)? A simple code example would also be helpful to get the ball rolling.
As for other questions on StackOverflow I have seen one question which is similar that says dapper is great for stored procedures but does not indicate if table valued functions are allowable.

Please note that Entity Framework Core also allows us to execute raw SQL query to make use of existing stored procedure. For more information about executing raw SQL queries with Entity Framework Core, you can check this doc:
https://learn.microsoft.com/en-us/ef/core/querying/raw-sql
Besides, if you want to implement it with ADO.NET approach, you can try to use Microsoft.Data.SqlClient that provides the data provider for Microsoft SQL Server.
https://devblogs.microsoft.com/dotnet/introducing-the-new-microsoftdatasqlclient/

Related

Is it possible to access an SQL database migrated using Django with a JavaScript ORM instead of raw SQL for a microservice architecture?

Suppose that I have an app where the models have been created using Django ORM and Django acts like an API for authentication and gives control to the relation model User using its ORM. At the same time, we want to use Express JS to continuously update a field in one the User model for some feature that requires performance. Is it possible to use a JavaScript ORM with Express JS to update such field? If yes, then how?
In the following tutorial tutorial for Golang, the database is created using SQL and a table called go_test_model is created. Then he uses the struct called GoTestModel to create a row in the table go_test_model.
This basically means that if we create an app called api in Django and add in it a model called Example, then to handle that model in Golang we just create a struct called ApiExample and from there we can have CRUD access to the same table, there might be some conflicts in the fields datatypes between GORM and Django ORM but integrity is still applied in the database itself.
So this particular example solves my problem with Golang and can be replicated using Node JS.
You can use Sequelize for using native functions for performing queries instead of writing raw queries.
Also, please refer to Models section to define models.

ASP.Net Core 2 - Query SQL without EFCore?

I'm new to Core 2 and am trying to connect to a SQL server to query some info.
I cant get EFCore to scaffold the database because it's an old DB with badly designed links, the scaffold kicks it out and won't work.
I can't alter the tables, it's read only. how can i get this to work, or, can i access the db in a different way? I cant find anything on google that doesn't use efcore.
Thanks,
There are a couple of solutions to achieve this. Since ASP.NET Core 2.0 implements .NET Standard 2.0, you can use ADO.NET with ASP.NET Core. So you can write stored procedure or query to get your data with dataset or datareader.
There are also other lightweight ORM tools like Dapper or NPoco. Both these ORMs allow developers to write SQL queries. Please refer to below posts to find out how to use them with ASP.NET Core
Use Dapper ORM With ASP.NET Core
Use NPoco ORM With ASP.NET Core

Business Connectivity Services for a large scale database having several stored procedures

I am working on a project having a large scale database with several stored procedures and I need to use the data in SharePoint 2013, the database is in SQL Server 2008 R2
According to my understanding I have two options:
1) is to create a Web service, using entity framework to interact with the database and most probably will use WebAPI. My logic will be in Stored procedures or DAL layer.
2) Secondly, I did a little research and got to know about the Business connectivity services provided by the SharePoint 2010/2013 as I am working with 2013 so I will be using visual studio 2012. Now learning more about the BCS I understood that I can map each table as a content type and then somehow define relationship. Anwyay, implementing BCS is a separate issue which I think I will somehow manage.
My question is how am I going to import/include my stored procedures? and if not stored procedures then where will I write my queries to get the data from the BCS?
Please direct me to right direction. Thank you.
Using a custom BCS connector you implement the way you want to retrieve the data from the DB (directly in C#), so you can query directly the table, or stored procedures.
If you want to try a BCS connector to create an external content type to use in SharePoint, take a look at my blog. My example is related to indexing sql data for the search, but the way it's done in SharePoint is creating an external content type, and this content type is the one that you index. So you'll find useful information on how to create that BCS connector.

Directing ADO queries away from the database

I've got a large number of old Delphi apps accessing a remote SQL Server database using ADO. I would like to get direct those queries to a middleware layer instead of said database. The Delphi clients must run unchanged; I am not the owner of most of them.
Is it possible to do this? If so, how should I go about it?
Don't worry about parsing the T-SQL (both raw T-SQL and stored proc calls, incidentally).
Create a new SQL database, and use a combination of views, T-SQL and managed code to fake up enough database objects for the application to work.
Technique 1: Use tables, but populate them asyncrhonously from the new data source.
Technique 2: Fake the tables and procedures
E.g. you can have a stored procedure which calls managed code to your middleware, to replace the existing stored procedure.
Where the application reads directly from a table, you can use a view, which references a managed table-valued function.
-
You should have no trouble wherever stored procedures are used. If the application sends dynamic SQL you have more of an uphill struggle however.

Execute complex query using Session (coldfusion.air.session class)

We are working on a sync application using ColdFusion 9.0.1 ActionScript ORM Library for AIR applications. Since this is application should work smoothly offline as well, there is a list of clients that has to be loaded when a user logs in, hence we are fetching data from all the required tables when application loads (is that the right way?). Now when we get the data from the required tables then based on the user who logs in we have to filter the clients, to filter this the query required is a complex one with joins between 5-6 tables and where clause. What I found that using the Coldfusion.Air.Session class we can only load objects of tables with simple where clause. There is non ORM way to load the data but I don't think that is the right method. Is there any method using this ORM framework to load data using such complex queries.
Thanks,
Gaurav
Are you using any CF code to send data back to your application? Have you tried HQL?
In other words you can write standard cfquery and dbtype="hql"
This will let you do almost anything you can do with a standard cfquery.
I am not directly familiar with the ActionScript ORM Library for AIR.