Need to get AbpUsers table data by conventional DbContext way.
See original GitHub issueHi dear @ismcagdas , @maliming , @acjh , @hikalkan , @alirizaadiyahsi I want to get the data from AbpUsers table in conventional way without using any repositories, UserManager Services etc.
Because, as I am converting my normal MVC source to ABP (#4234) it is impossible to change all the existing code to ABP standards. So my plan is to run the existing code as it is and follow ABP style for further development. I am very happy that it is almost successful and running.
Currently I am facing an important issue regarding the eager loading of AbpUsers table. Not only for eager loading, but also even i can’t get results of querying the AbpUsers table directly.
My Linq query in Controller is given below. The controller is derived from ABMControllerBase only (ABM is the project name):
private ABMDbContext db = new ABMDbContext();
var result = db.POMasters
.Include(x => x.PORevisionRemarks.Select(c => c.UserMaster))
.Include(x => x.UserMaster)
.Where(x => !x.IsDeleted && x.IsSubmitted)
.MapTo<List<POMasterListDto>>();
// Trying to get the Users list by conventional way just for testing.
// But unfortunately, this also returns null
var userList = db.Users.ToList();
Without including the UserMaster and PORevisionRemarks.UserMaster, the query runs smoothly. Also I can get results when including only PORevisionRemarks too.
When using the given query, I am getting the following error:
The transaction has aborted.
System.Transactions.TransactionAbortedException: The transaction has aborted. --->
System.Data.SqlClient.SqlException: The transaction operation cannot be performed because there are pending requests working on this transaction.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest)
at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction(TransactionRequest transactionRequest, String name, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
at System.Data.SqlClient.SqlDelegatedTransaction.SinglePhaseCommit(SinglePhaseEnlistment enlistment)
--- End of inner exception stack trace ---
at System.Transactions.TransactionStateAborted.EndCommit(InternalTransaction tx)
at System.Transactions.CommittableTransaction.Commit()
at System.Transactions.TransactionScope.InternalDispose()
at System.Transactions.TransactionScope.Dispose()
at Abp.EntityFramework.Uow.TransactionScopeEfTransactionStrategy.Commit()
at Abp.EntityFramework.Uow.EfUnitOfWork.CompleteUow()
at Abp.Domain.Uow.UnitOfWorkBase.Complete()
at Abp.Web.Mvc.Uow.AbpMvcUowFilter.OnActionExecuted(ActionExecutedContext filterContext)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_1.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_1.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_1.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_1.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass7_0.<BeginInvokeActionMethodWithFilters>b__1(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass3_6.<BeginInvokeAction>b__3()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass3_1.<BeginInvokeAction>b__5(IAsyncResult asyncResult)
The PORevisionRemark class:
public partial class PORevisionRemark
{
public long Id { get; set; }
public long POMasterId { get; set; }
public string PONo { get; set; }
public int RevisionNo { get; set; }
public string Remarks { get; set; }
public long RevisedBy { get; set; }
[ForeignKey("RevisedBy")]
public virtual User UserMaster { get; set; }
public System.DateTime RevisedOn { get; set; }
public virtual POMaster POMaster { get; set; }
}
Also I have given a custom mapping between POMaster and POMasterListDto as follows:
cfg.CreateMap<POMaster, POMasterListDto>()
.ForMember(dt => dt.CreatedUserName, op => op.MapFrom(s => s.UserMaster.Name ?? "User not Found"))
.ForMember(dt => dt.RevisedUserName, op => op.MapFrom(s => s.PORevisionRemarks.Where(z => z.RevisionNo == s.CurrentRevisionNo).FirstOrDefault() == null ? "" : s.PORevisionRemarks.Where(z => z.RevisionNo == s.CurrentRevisionNo).FirstOrDefault().UserMaster.Name))
The same code is running successfully in my old project with another table instead of AbpUsers. Please help me out.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
@sayassyk Try not to create objects manually, using dependency injection. https://github.com/sayassyk/module-zero-template/blob/master/src/AbpCompanyName.AbpProjectName.WebMpa/Controllers/UsersController.cs#L36
Made my day!! It worked!!! Thank you so much @maliming , @ismcagdas , @ryancyq for your awesome support!