@ismcagdas,
We have used DateTime.UtcNow to populate all of our custom datetime fields. But the ABP fields (CreationTime, DeletionTime, LastModificationTime) all use local time. Our current work-around is to run our Azure servers in UTC, which assures that all DateTime fields are stored in UTC. But it's time to make a proper fix.
We are using AspNetZero v8.4, Abp 5.5, Mvc/jQuery.
Will you please provide an example of how to change the clock provider in ConfigureServices?
Based upon earlier posts in this thread, it looks like we should go back and replace all "DateTime.UtcNow" references with "ClockProviders.Utc.Now". Do you advise that change?
Thanks, BigC
The code sample above looks like it may have a logical error. If person is not null, then you are trying to insert that person into the repository again? And if person is null, then you are trying to insert a null into the repository? I don't understand.
Maybe this line below is supposed to insert the new record rather than old person?
record.Id = _personRepository.InsertAndGetId(person);
should be
record.Id = _personRepository.InsertAndGetId(record);
If that's the case, I think you only need to capture the output if you intend to use the new Id immediately for some cross-referenced object. You don't have to reset record.Id = record.Id. For example...
var newId = _personRepository.InsertAndGetId(record);
callLog.PersonId = newId;
_callLogRepository.Update(callLog);
AspNetZero v8.4, Abp 5.5, Mvc/jQuery.
ORIGINAL MESSAGE SENT BY EMAIL
We have a query that suffers from parameter sniffing, where execution of the EF-generated query takes 10 seconds to return 1 row, but if you can convert it to T-SQL, it executes immediately. If I were to solve this problem using a Microsoft-centric mindset, I would add code similar to this link: Interceptors - EF Core | Microsoft Docs
var blogs1 = context.Blogs.TagWith("Use hint: recompile plan").ToList();
That EF statement would then generate SQL that looked like this: -- Use hint: robust plan
SELECT [b].[Id], [b].[Name] FROM [Blogs] AS [b] OPTION (RECOMPILE)
In the EF6 days, I used this same technique with success, and it looked like this: How to add OPTION RECOMPILE into Entity Framework - Stack Overflow
Is there a sample that you can point to where the ASP.NET Zero classes can enable per-context/per-statement query hint generation?
Thanks for any help.
<br>
ORIGINAL RESPONSE RECEIVED BY EMAIL
I think you are trying to detect the cause of the problem. If so, you can inject IDbContextProvider and get the DbContext using this class and execute a method like you have shared in your email for including recompile plan.
If this is not for detecting the problem, then you can create a custom repository (https://aspnetboilerplate.com/Pages/Documents/Repositories#custom-repositories) and place the same query in it.
<br> <br>
UPDATED QUESTION
Is there a ready-made sample available somewhere that would show how to implement the EF Core Interceptor (TaggedQueryCommandInterceptor [ref: https://docs.microsoft.com/en-us/ef/core/logging-events-diagnostics/interceptors]) in an ABP repository? We have code that looks like this in an AppService:
private readonly IRepository<OrganizationUnit, long> _organizationUnitRepository;
public async Task<GetUserForEditOutput> GetUserForEdit(NullableIdDto<long> input) { var allOrganizationUnits1 = await _organizationUnitRepository.GetAllListAsync(); … }
I would love to be able to specify the query hint on an individual query, based on our investigation into whether a specific query will need it or not. So the last statement would maybe look something like: var allOrganizationUnits1 = await _organizationUnitRepository.OptionRecompile().GetAllListAsync();
and the resulting query would use the EF interceptor to add the OPTION RECOMPILE SQL query hint.
Thanks again.
AspNetZero v8.4, Abp 5.5, Mvc/jQuery.
Under the profile icon, if you click on "Manage linked accounts", close the dialog, and then immediately click on the "Manage linked accounts" again, the system throws a datatables reinitialization error.
Because this is a timing issue, you may have to perform the process a few times. However, it is a very repeatable.bug.
Although the "Manage authority delegations" option functions very similarly, this menu option does NOT exhibit the same behavior...and may be a key to helping figure out what is different between the two.
I figured, just maybe the AuthorizationProvider is not being loaded. So, I added this line to thePreInitialize() of [MyProject]TestBaseModule. <br>
Configuration.Authorization.Providers.Add<AppAuthorizationProvider>();
This gave me an error: <br>
Message:
Abp.AbpInitializationException : Duplicate permission name detected for Pages.Accounts
Stack Trace:
PermissionDictionary.AddPermissionRecursively(Permission permission)
PermissionDictionary.AddPermissionRecursively(Permission permission)
PermissionDictionary.AddAllPermissions()
PermissionManager.Initialize()
AbpKernelModule.PostInitialize()
<>c.<StartModules>b__15_2(AbpModuleInfo module)
List`1.ForEach(Action`1 action)
AbpModuleManager.StartModules()
AbpBootstrapper.Initialize()
AbpIntegratedTestBase`1.InitializeAbp()
AbpIntegratedTestBase`1.ctor(Boolean initializeAbp, IIocManager localIocManager)
AppTestBase`1.ctor() line 40
AppTestBase.ctor()
TenantAppService_Tests.ctor() line 30
So, we know for certain the AuthorizationProvider is being loaded.
AspNetZero v8.6 MVC/jQuery .Net Core Abp.TestBase v5.5
When I connect my unit tests to a SQLServer database, I am able to call application services with appropriate permissions. When I switch to using the in-memory SQLLite database, the [MyProject]AuthorizationHelper.PermissionChecker.AuthorizeAsync throws an exception.
As far as I can tell, there is either (A) an issue with the data being different betweeen the two databases or (B) an issue with the Abp code/handlers associated with SQLLite.
I have meticulously recreated the SQLServer database in the [MyProject].Test.Base.TestData.TestDataBuilder population of the SQLLite instance. So, I'm now leaning toward option B.
public class TestDataBuilder : ITestDataBuilder
{
protected readonly PGSAspectDbContext _context;
protected readonly int _tenantId;
protected readonly RoleManager roleManager;
protected readonly UserManager userManager;
protected readonly TenantManager tenantManager;
protected readonly ISessionTenantFilterList sessionTenantFilterList;
public TestDataBuilder(PGSAspectDbContext context, int tenantId, TenantManager tenantManager, UserManager userManager, RoleManager roleManager, ISessionTenantFilterList sessionTenantFilterList)
{
_context = context;
_tenantId = tenantId;
this.roleManager = roleManager;
this.userManager = userManager;
this.tenantManager = tenantManager;
this.sessionTenantFilterList = sessionTenantFilterList;
}
public virtual void Create()
{
_context.SaveChanges();
new TestData_AbpEditions(_context).Create();
new TestData_AbpUsersHost(userManager, roleManager).Create(); _context.SaveChanges();
new TestData_AbpTenants(tenantManager, roleManager).Create(); _context.SaveChanges(); // Prerequisites: Edition
new TestData_AbpSettings(_context).Create(); // Prerequisites: Tenant
new TestData_AbpFeatures(_context).Create(); // Prerequisites: Edition, Tenant
new TestData_AbpRoles(_context).Create(); // Prerequisites: Tenant
new TestData_AbpUsers(userManager, roleManager).Create(); _context.SaveChanges(); // Prerequisites: Tenant, Roles
new TestData_AbpUserAccounts(_context).Create(); // Prerequisites: Tenant, Users
new TestData_AbpPermissions(_context).Create(); // Prerequisites: Tenant, Roles, Users
new TestData_Clients(_context).Create();
new TestData_AbpOrganizationUnits(_context, sessionTenantFilterList).Create();
_context.SaveChanges();
}
}
NOTE: We are using MultiTenancy and we are highly integrated into the OrganizationalUnits. The ISessionTenantFilterList is our set of custom filters that allow us to expose data up and down the OrganizationalUnit hierarchy based upon Edition, Organziational Level, and TEntity. (I am certain this issue is unrelated to our custom filters, though I have not yet ruled out the possibility that it is related to MultiTenancy.)
Here is the test that triggers the error....
[MultiTenantFact]
public async Task Test_Create()
{
//Arrange
LoginAsTenant("xxx", "admin");
var mockInput = new FakeCreateOrEditStoreDto();
//Act
await _storesAppService.CreateOrEdit(mockInput);
//Assert
UsingDbContext(context =>
{
var store = context.Stores.FirstOrDefault(e => e.UID == mockInput.UID);
store.ShouldNotBeNull();
store.Name.ShouldBe(mockInput.Name);
});
}
The error reiceved looks like this...
I noticed that trapping the breakpoint BEFORE execution of PermissionChecker, there are no ActiveDbContexts (see below).
AFTER execution/exception, an ActiveDbContext reference has been set, but there are no permissions available (see below).
If I click on the Results View, the context is refreshed and the permissions become available (see below).
When I change to using LoginAsHost("admin"), I get a different but seemingly related error (see below).
I am probably doing something stupid, but any insights that you can offer are greatly appreciated.
Files have been sent via email.
AspNetZero 7.2 MVC / jQuery.
I seriously hope I'm not doing something stupid-easy and wasting your time with this one, but I just don't see it.
When attempting to import users from an excel spreadsheet, the individual user records are rejected with a "Nullable object must have a value" error. Then, the try-catch builds the list of these invalid users and when attempting to publish the notification fails again with the same error.
Here are the records in the import file. <br> | UserName* | Name* | Last Name* | EmailAddress* | PhoneNumber | Password* | AssignedRoleNames (comma separated) | | --------- | ----- | ---------- | ------------- | ----------- | --------- | ----------------------------------- | | Mickey | Mickey | Mouse | [email protected] | 2342342345 | 123qwe | User | | Minnie | Minnie | Mouse | [email protected] | 2342342346 | 123qwe | Admin | | Donald | Donald | Duck | [email protected] | 2342342347 | 123qwe | User | | Daisy | Daisy | Duck | [email protected] | 2342342348 | 123qwe | Admin | | Scrooge | Scrooge | McDuck | [email protected] | 2342342349 | 123qwe | Admin | <br> Here are the two images of the locations where the errors are occurring.
A working solution has been documented at the GitHub link above.