tomsrapper
New Member
- Joined
- Oct 24, 2018
- Messages
- 2
- Reaction score
- 0
You can connect to sql server using multiple protocol libraries, check this: Sql server connection
South Africa’s biggest forum. Discuss, discover, and connect with thousands of members.
public async Task AutoInvoiceCreate()
{
await Task.Run(() =>
{
try
{
using (SqlConnection conn = new SqlConnection(base.ConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("autoInvoiceCreation", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
ErrorLogger.LogMessage("InvoicePreview", "PreviewDAL", "AutoInvoiceCreate()", ex.Message);
}
});
}
await db.AutoInvoiceCreate();
public async Task AutoInvoiceCreate()
{
await Task.Run(() =>
{
try
{
using (SqlConnection conn = new SqlConnection(base.ConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("autoInvoiceCreation", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
ErrorLogger.LogMessage("InvoicePreview", "PreviewDAL", "AutoInvoiceCreate()", ex.Message);
}
});
}
await db.AutoInvoiceCreate();
I won't like the generic one I'm using, might be a bit confusing. This is one I'm using for one of my clients, works well. While it's processing 2500 invoices I have a progress bar running on the UI so it doesn't freeze up.
better option might be to use something like Hangfire - https://www.hangfire.io/
I don't find Dapper or ORMs useful; far easier to build a simple API without this dependency.Have you thought of using EF or EFCore with DbContext? (Depending on your target platform) then use Dapper for CRUD operations. Just my thoughts though. It would be a lot cleaner to maintain in a long run![]()
I don't find Dapper or ORMs useful; far easier to build a simple API without this dependency.
Agreed. You would abstract the persistence with an interface (API) anyway to loosely couple it to whatever implementation you chooseHave you used Dapper at all? Forget EF. Dapper specifically.
I find it's quite useful in getting work done, and I don't have to write a single "using" statement or open / close database connections etc. It maps my objects correctly and even if the object and/or stored procedure changes, it automatically adapts and there is no ORM logic I have to change....
Post your simple API version here so we can learn from you. i love working without silly little dependencies
Yes, and I've also removed a lot of Dapper and other ORMs from codebases. Why is another debate entirely.Have you used Dapper at all? Forget EF. Dapper specifically.
I find it's quite useful in getting work done, and I don't have to write a single "using" statement or open / close database connections etc. It maps my objects correctly and even if the object and/or stored procedure changes, it automatically adapts and there is no ORM logic I have to change....
Post your simple API version here so we can learn from you. i love working without silly little dependencies
Yes, and I've also removed a lot of Dapper and other ORMs from codebases. Why is another debate entirely.
As for building simple, concise and stable APIs, I have already shared some of the basics in my functional threads; the last thread focused on a few examples of exception handling, decoupling data validation code from constructors and building a single API for SqlClient and SQLite.
If you like very terse APIs, it easy to compose this down to a single extension method, that's still flexible I.e. a higher order function like those use by Linq.
Company I'm with wants to move to EF. My first question was "why?"
I'm not a fan of this; there have been many attempts to simplify SQL and the computations around it; EF and ORMs have not magically made things simpler. Some simply use them because the API is a bit more streamlined, but as I tried to show there are other ways to tackle this problem that can deliver far more terse APIs without the overhead of an ORM.Company I'm with wants to move to EF. My first question was "why?"
As yet I've not received a straight forward answer.
![]()
I too find it unnecessary complex; but it's not the end of the world if a project chooses to use it.I'm going to try and talk them out of it. Also at this phase of crucial new development I think it would be counterproductive aka it's not going to make things easier. You've made some excellent points Roi. One thing to add I find that ORMs do not make for a neat project in general and the whole thing just feels like it's been wrapped in creeper vines all tightly interwoven whereas I like many others prefer a loose coupling of everything. Simplicity is the highest form of complexity.