DbSharpApplication is a C# source code generator. It generates a stored procedure client class that enables you to call stored procedure easily. DbSharpApplication also creates user defined table type classes. Latest update 2024.01.26.
Introduction
DbSharpApplication
is a new version of the article, DbSharp -DAL Generator Tool on .NET6, which I posted just 10 years ago.
Last year, I decided to enhance its design. I started from scratch, eliminated redundant features, and redesigned it for ease of use.
Feature Summary
DbSharpApplication
generates C# code. You set up project and add some of the references via Nuget.
Now you can easily call stored procedure like this:
var sp = new Usp_Structure();
sp.BigIntColumn = 1;
var r = new MyTableType.Record();
r.BigIntColumn = 2;
sp.StructuredColumn.Records.Add(r);
var spResult = await sp.ExecuteNonQueryAsync();
var sp1 = new Usp_SelectMultiTable();
var resultSetList = await sp1.GetResultSetsListAsync();
foreach (var item in resultSetList.ResultSetList)
{
var text = item.CharColumn;
Console.WriteLine(item.BigIntColumn);
}
You can call easily call stored procedure from C#. Generated classes are strong typed, so you can select by intellisense.
DbSharpApplication supports Table Value Parameter, out parameter, resultset, enum values, and so on. DbSharpApplication continues to provide the functionality of the previous version on .NET6. You can see it by this article.
DbSharp -DAL Generator Tool on .NET6
How to Generate and Setup Project
- Download
DbSharpApplication
. - Set up connection string of database.
- Generate C# source code to project.
- Add reference from Nuget.
Download DbSharpApplication
You can download from this link.
Launch .exe
Set Up generate setting
You can generate setting by press Add button in left panel.
Add connection string by Settings button. Window will open.
You can add your connection string list.
These connection string will saved to file at user folder.
ex) C:\Users\Higty\HigLabo\DbSharpApplication\ConfigData.xml
Generate C# Source Code
Select connection string that you added before, button is shown.
Press Load stored procedure button. Stored procedure list are loaded.
Select stored procedure and press Generate button at the bottom.
Stored procedure parameters are loaded.
Set output folder, namespace, database key. Press Generate button. C# source code will be generated to specified folder.
If stored procedure has resultset
, press Load result set button.
Resultset
is loaded.
Add Reference from Nuget
To compile project, you must add reference of these.
HigLabo.Core
HigLabo.Data
HigLabo.Data.SqlServer
HigLabo.DbSharp
HigLabo.DbSharp.SqlServer
Now, you can compile the project.
I created a sample project on GitHub.
How to Use the Class
Set up DatabaseFactory
class. If you set Database key "HigLabo
", you pass "HigLabo
" to the first parameter.
StoredProcedure.DatabaseFactory.SetCreateDatabaseMethod
("HigLabo", () => new SqlServerDatabase("My connection string..."));
Now, you can easily call stored procedure with user defined table type.
var sp = new Usp_Structure();
sp.BigIntColumn = 1;
var r = new MyTableType.Record();
r.BigIntColumn = 2;
sp.StructuredColumn.Records.Add(r);
var spResult = await sp.ExecuteNonQueryAsync();
You can get result set.
var sp1 = new Usp_SelectMultiTable();
var resultSetList = await sp1.GetResultSetsListAsync();
foreach (var item in resultSetList.ResultSetList)
{
var text = item.CharColumn;
Console.WriteLine(item.BigIntColumn);
}
You can see the sample code at the link below:
Conclusion
DbSharpApplication
is not ORM, it is a generator of DAL. Once C# code is generated, you can easily call it.
History
- 26th January, 2024: Initial version
- 2nd February, DbSharpApplication updated to 8.1.0.0