The problem is I set the TenantID in the browser before redirecting the user to Okta. So when Okta authenticates I just use the TenantID and token and log that user
But when you are using the API , I am not sure how to pass the TenantID
Thank you I completely removed the Automapper from the custiom code. Didn't make any sense to use it .
But this should have been marked as a breaking change
var output = new GetTemplateForEditOutput { Template = ObjectMapper.Map<CreateOrEditTemplateDto>(template) };
This is where it's errroing
Thank you @ismcagdas. But I am already using a secondary db context to get data. I figured the problem with the dependency Injection.
The last piece i am unable to figure out is the GetActiveTransaction() part.
public class SecondaryDBDBHelperMethods : ITransientDependency
{
private readonly IActiveTransactionProvider _transactionProvider;
private readonly IDbContextProvider<SecondaryDBDbContext> _SecondaryDBDbContext;
public SecondaryDBDBHelperMethods(IActiveTransactionProvider transactionProvider, IDbContextProvider<SecondaryDBDbContext> SecondaryDBDbContext)
{
_transactionProvider = transactionProvider;
_SecondaryDBDbContext = SecondaryDBDbContext;
}
public async Task<ArrayList> GetStoredProcedureResult(string storedProcedureName, SqlParameter[] parameters)
{
EnsureConnectionOpen();
ArrayList rowList = new ArrayList();
using (var command = CreateCommand(storedProcedureName, CommandType.StoredProcedure, parameters))
{
using (var dataReader = await command.ExecuteReaderAsync())
{
while (dataReader.Read())
{
object[] values = new object[dataReader.FieldCount];
dataReader.GetValues(values);
rowList.Add(values);
}
return rowList;
}
}
}
private DbCommand CreateCommand(string commandText, CommandType commandType, params SqlParameter[] parameters)
{
var command = _SecondaryDBDbContext.GetDbContext().Database.GetDbConnection().CreateCommand();
command.CommandText = commandText;
command.CommandType = commandType;
// command.Transaction = GetActiveTransaction();
foreach (var parameter in parameters)
{
command.Parameters.Add(parameter);
}
return command;
}
private void EnsureConnectionOpen()
{
var connection = _SecondaryDBDbContext.GetDbContext().Database.GetDbConnection();
if (connection.State != ConnectionState.Open)
{
connection.Open();
}
}
private DbTransaction GetActiveTransaction()
{
return (DbTransaction)_transactionProvider.GetActiveTransaction(new ActiveTransactionProviderArgs
{
{"ContextType", typeof(SecondarybContext) },
{"MultiTenancySide", MultiTenancySide }
});
}
}
How can i get a ActiveTransaction from the secondary database ? Or do I need to change something
Below is the class I wrote in EFCore :
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Text;
using System.Threading.Tasks;
using Abp.Data;
using Abp.Dependency;
using Microsoft.AspNetCore.Hosting.Internal;
using Microsoft.EntityFrameworkCore;
namespace YYY.AAA.EntityFrameworkCore
{
public class xxxxDBHelperMethods : ITransientDependency
{
private readonly IActiveTransactionProvider _transactionProvider;
private readonly xxxxDbContext _xxxxDbContext;
public xxxxDBHelperMethods(IActiveTransactionProvider transactionProvider, xxxxDbContext xxxxDbContext)
{
_transactionProvider = transactionProvider;
_xxxxDbContext = xxxxDbContext;
}
public async Task<ArrayList> GetStoredProcedureResult(string storedProcedureName, SqlParameter[] parameters)
{
EnsureConnectionOpen();
ArrayList rowList = new ArrayList();
using (var command = CreateCommand(storedProcedureName, CommandType.StoredProcedure, parameters))
{
using (var dataReader = await command.ExecuteReaderAsync())
{
while (dataReader.Read())
{
object[] values = new object[dataReader.FieldCount];
dataReader.GetValues(values);
rowList.Add(values);
}
return rowList;
}
}
}
private DbCommand CreateCommand(string commandText, CommandType commandType, params SqlParameter[] parameters)
{
var command = _xxxxDbContext.Database.GetDbConnection().CreateCommand();
command.CommandText = commandText;
command.CommandType = commandType;
command.Transaction = GetActiveTransaction();
foreach (var parameter in parameters)
{
command.Parameters.Add(parameter);
}
return command;
}
private void EnsureConnectionOpen()
{
var connection = _xxxxDbContext.Database.GetDbConnection();
if (connection.State != ConnectionState.Open)
{
connection.Open();
}
}
private DbTransaction GetActiveTransaction()
{
return (DbTransaction)_transactionProvider.GetActiveTransaction(new ActiveTransactionProviderArgs
{
{"ContextType", typeof(xxxxDbContext) }
});
}
}
}
Below is the class I wrote in my Application Project :
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using System.Threading.Tasks;
using YYY.AAA.EntityFrameworkCore;
namespace YYY.AAA.Reporting
{
public class ReportingAppServices : AAAAppServiceBase, IReportingAppServices
{
private readonly xxxxDBHelperMethods _xxxxDbHelperMethods;
public ReportingAppServices(xxxxDBHelperMethods xxxxDbHelperMethods)
{
_xxxxDbHelperMethods = xxxxDbHelperMethods;
}
public Task<ArrayList> GetReportDataFromxxxx(int id)
{
SqlParameter param = new SqlParameter { ParameterName = "@id", Value = id, };
SqlParameter[] parameters = new SqlParameter[1];
parameters[0] = param;
return _xxxxDbHelperMethods.GetStoredProcedureResult("[xxxx].[TestStoredProcedure]", parameters);
}
}
}
This is a test, and I am getting the below error :
2019-06-27 16:35:27,613 [6 ] Mvc.ExceptionHandling.AbpExceptionFilter - Can't create component 'CASTANDCREW.FMS.EntityFrameworkCore.CAPSPayDbContext' as it has dependencies to be satisfied. 'CASTANDCREW.FMS.EntityFrameworkCore.CAPSPayDbContext' is waiting for the following dependencies:
Is this the rightway to do this ? and why am I getting dependency injection error
I am having the same problem, And I have set Clock.Provider = ClockProviders.Utc; Now I am storing dates which I don't want to be converted and store the data as it is.
In order to do that what I need to do so that it deosn't convert and store the data as it is.
I am sorry but i am still not able to proceed far. I think I am unable to understand the concepts here. Let me put that into some perspective :
I have two DBContext Context A and Context B. Context A is Abp database and Context B is let's say Adventureworks database.
I need to call a stoired procedure in Adventureworks database.
The article written in the link talks about using repository pattern accessing a table and getting a defined result. What I plan to do is build an interface where users are going to declare the stored procedure name, and the parameters and I should be able to execute this in Adventureworks and get the result back.
I tried creating a AdventureRepository base but couldn't move forward. Can you please me further, i am kind of stuck here?
I injected IOnlineClientManager but didn't see GetByUserIdorNull rather it's GetAllByUserId. And there is no clear documentation on how to get the number of active users. Any help is appreciated.
No this didn't work, but when i increased the RAM it got resolved temporarily but keeps getting back now and then
No it didn't solve. for the time being i am compiling without --prod