ConnectionManager Replacement #3287
-
I am updating a Csla4/.Net Framework/Ado.Net library of 40+ classes to Csla6.2.2/.Net6. I implemented EFCore7 in the rewrite, but quickly found out EF cannot duplicate some of the things that we were doing in Ado.Net (multiple joins, etc.), at least until EFCore8, or possibly later. So I am switching back to implementing Ado,Net in the new environment. I found guidance in this post, with a reply by Rocky: https://stackoverflow.com/questions/72295421/upgrade-to-csla-6-connectionmanager-problem
My problem is with "// initialize the connection here". In Csla4, ConnectionManager established the connection. You just fed it the config file key. I've spent a full day searching the net for an answer, but nothing seems to work. Here's what I currently have (Blazor app):
On the GetConnectionString line I am getting the error: "Error CS1660 Cannot convert lambda expression to type 'Type' because it is not a delegate type". Can anyone steer me to what should be there instead? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
I am in the same boat, we have several applications in Csla 4.xx , would love to update them to 6.xx. |
Beta Was this translation helpful? Give feedback.
-
I've upgraded to CSLA 6 and took a slightly different approach than Rocky's example that I think is a little closer in use to using connection manager. First I created a class that will take the connection string and return a new opened SQLConnection. public class DbConnect
{
private string ConnectionString { get; set; }
public DbConnect(string connectionString)
{
ConnectionString = connectionString;
}
public SqlConnection GetConnection()
{
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
return conn;
}
} Then in my program.cs I'm adding the class to the services collection: builder.Services.AddScoped<DbConnect>(options => new DbConnect(builder.Configuration.GetConnectionString("ConnectionStringName"))); Then I inject that class into my DAL object and use it similarly to the connection manager: public partial class ClientNoteDal : IClientNoteDal
{
private DbConnect DalDb { get; set; }
public ClientNoteDal(DbConnect dalDb)
{
DalDb = dalDb;
}
public ClientNoteDto Fetch(int noteID)
{
using (var ctx = DalDb.GetConnection())
{
using (var cmd = new SqlCommand("procNotesByNoteID_Select", ctx))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@NoteID", noteID).DbType = DbType.Int32;
var dr = cmd.ExecuteReader();
var data = Fetch(dr);
return data;
}
}
}
private ClientNoteDto Fetch(IDataReader data)
{
var clientNote = new ClientNoteDto();
using (var dr = new SafeDataReader(data))
{
if (dr.Read())
{
clientNote.NoteID = dr.GetInt32("NoteID");
clientNote.Subject = dr.GetString("Subject");
clientNote.Note = dr.GetString("Note");
clientNote.DateOfNote = dr.GetSmartDate("DateOfNote", true);
clientNote.ClientID = (int?)dr.GetValue("ClientID");
}
}
return clientNote;
}
} This way I can put the connection in a using statement at the point that it needs to run the command and it will be immediately closed and disposed of when the Fetch method is finished. |
Beta Was this translation helpful? Give feedback.
-
I added a link to this thread from the upgrading to CSLA 6 doc. |
Beta Was this translation helpful? Give feedback.
-
I have ported my Csla 5 to the latest Csla 8 code and are running into an issue with transaction handling in my DAL. I am receiving 2 types of errors
I am using ADO.NET code in my DAL. I am also using the transaction scope attributes in the data portal call in the business object e.g. [Transactional(TransactionalTypes.TransactionScope)] This is my connection class:
Calls to the connection is wrapped in using statements e.g.:
A few questions comes to mind:
|
Beta Was this translation helpful? Give feedback.
I've upgraded to CSLA 6 and took a slightly different approach than Rocky's example that I think is a little closer in use to using connection manager. First I created a class that will take the connection string and return a new opened SQLConnection.
Then in my program.cs I'm adding the class to the …