Hi,
Is it possible to write a linq to sql query that contains an entity string property (FullScarNumer) derived from another int property of the same entity (Scar number)
I would basically like to search for this FullScarNumber using the usual search by term and advance search fields. It seems that EF Core 3. 0 does not like this .
Search query. I tried String.Format also to see if it would work.
Is this possible with the new EF Core?
Error: ERROR 2020-04-28 11:25:47,036 [36 ] Mvc.ExceptionHandling.AbpExceptionFilter - The LINQ expression 'DbSet<Scar>
.Where(s => __ef_filter__p_0 || !(((ISoftDelete)s).IsDeleted))
.Join(
outer: DbSet<Category>,
inner: s => EF.Property<Nullable<int>>(s, "CategoryId"),
outerKeySelector: c => EF.Property<Nullable<int>>(c, "Id"),
innerKeySelector: (o, i) => new TransparentIdentifier<Scar, Category>(
Outer = o,
Inner = i
))
.LeftJoin(
outer: DbSet<ScarStatus>
.Where(s0 => __ef_filter__p_1 || !(((ISoftDelete)s0).IsDeleted)),
inner: s => EF.Property<Nullable<int>>(s.Outer, "StatusId"),
outerKeySelector: s0 => EF.Property<Nullable<int>>(s0, "Id"),
innerKeySelector: (o, i) => new TransparentIdentifier<TransparentIdentifier<Scar, Category>, ScarStatus>(
Outer = o,
Inner = i
))
.Where(s => False || s.Outer.Outer.Title.ToLower().Contains(__Trim_0) || string.Format(
format: "{0,00000}",
arg0: (object)s.Outer.Outer.ScarNumber).ToLower().Contains(__Trim_0) || s.Outer.Inner.Name.ToLower().Contains(__Trim_0) || s.Inner.Name.ToLower().Contains(__Trim_0))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
System.InvalidOperationException: The LINQ expression 'DbSet<Scar>
.Where(s => __ef_filter__p_0 || !(((ISoftDelete)s).IsDeleted))
.Join(
outer: DbSet<Category>,
inner: s => EF.Property<Nullable<int>>(s, "CategoryId"),
outerKeySelector: c => EF.Property<Nullable<int>>(c, "Id"),
innerKeySelector: (o, i) => new TransparentIdentifier<Scar, Category>(
Outer = o,
Inner = i
))
.LeftJoin(
outer: DbSet<ScarStatus>
.Where(s0 => __ef_filter__p_1 || !(((ISoftDelete)s0).IsDeleted)),
inner: s => EF.Property<Nullable<int>>(s.Outer, "StatusId"),
outerKeySelector: s0 => EF.Property<Nullable<int>>(s0, "Id"),
innerKeySelector: (o, i) => new TransparentIdentifier<TransparentIdentifier<Scar, Category>, ScarStatus>(
Outer = o,
Inner = i
))
.Where(s => False || s.Outer.Outer.Title.ToLower().Contains(__Trim_0) || string.Format(
format: "{0,00000}",
arg0: (object)s.Outer.Outer.ScarNumber).ToLower().Contains(__Trim_0) || s.Outer.Inner.Name.ToLower().Contains(__Trim_0) || s.Inner.Name.ToLower().Contains(__Trim_0))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.<VisitMethodCall>g__CheckTranslated|8_0(ShapedQueryExpression translated, <>c__DisplayClass8_0& )
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass12_01.<ExecuteAsync>b__0() at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func
1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable1 source, Expression expression, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable
1 source, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.CountAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at Bowie.Framework.Portal.Scars.ScarsAppService.GetAll(GetAllScarsInput input) in C:\Users\Eamon\Source\Repos\SPG_QMS\Portal\aspnet-core\src\Bowie.Framework.Portal.Application\Scars\ScarsAppService.cs:line 101
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.
Hello, we just had an issue where the resolution was to do a hard refresh. We are using Abp.ZeroCore v4.4.0.
I've seen this post https://support.aspnetzero.com/QA/Questions/6550 As stated there "I would want to figure out a good way to only do it on the first page load just after a new build only."
Hi,
It seems like the behaviour of the AbpUserManager.DeleteAsync has changed.
I have tables that have a FK reference to the userIds in the AbpUser table.
Previously, when I called DeleteAsync on a user, the records in these tables were not deleted and the user record IsDeleted flag was set to true.
However, when I use the DeleteAsync method now, the solution deletes any records that were associated with that user . The record in the AbpUsers table is still marked as IsDeleted = true however (still a soft delete).
Has something changed in the behaviour in how deletes are handled by ABP ?
Thanks in advance.
Hello I have an entity Xs it has a 1 to 1 relationship to XEffectiveness
[Table("Xs")]
public class X : FullAuditedEntity
{
public virtual int? Effectiveness { get; set; }
[ForeignKey("Effectiveness")]
public XEffectiveness EffectiveneFk { get; set; }
}
[Table("XEffectivenesses")]
public class XEffectiveness : FullAuditedEntity
{
public virtual int XId { get; set; }
public virtual X X { get; set; }
}
When I create a new record it successfully populates both tables correctly. However when I go to update the records it fails with Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Cannot insert explicit value for identity column in table 'XEffectivenesses' when IDENTITY_INSERT is set to OFF.
My PortalDBContext.cs has the following:
modelBuilder.Entity<X>()
.HasOne(x=> x.EffectiveneFk)
.WithOne(u => u.X)
.HasForeignKey<XEffectiveness>(b => b.XId);
To workaround the issue I have enacted the following:
private async Task<int> Update(CreateOrEditXDto input)
{
var x = await _xRepository.FirstOrDefaultAsync((int)input.Id);
ObjectMapper.Map(input, x);
var TEMPeffectiveness = x.EffectiveneFk;
x.EffectiveneFk = null;
await _xRepository.UpdateAsync(x);
await _lookup_xEffectivenessRepository.InsertOrUpdateAsync(TEMPeffectiveness);
return x.Id;
}
Which essentially takes out the 1 to 1 of Effectiveness temporarily, saves the parent of the 1 to 1 which is X and then saves the Effectiveness.
I have asked also on stackoverflow and will update both if I get an answer.
I would like to create two entities
Student and StudentInfo The end goal would be to see a list of students and then being able to go into a tab of that student to see its StudentInfo.
How would I go about starting this with the RAD tool? I was thinking of creating the Student entity first and having it appear on the Root and then the StudentInfo which would not have a menu position... Then going back to Student and adding a Navigation Property of StudentInfo.
Hi there.
In the Entity History Docs (https://github.com/aspnetboilerplate/aspnetboilerplate/blob/master/doc/WebSite/Entity-History.md) there is a reference to the IEntitySnapshotManager interface and GetSnapshotAsync methods but there is no reference in the ABP or Zero framework?
Does this exist and if not, what is the purpose of this in the docs?
Regards John
Hi, this morning our app went down on production and needed to be restarted from Azure. Looking at the logs the last thing to happen was:
DEBUG 2019-12-14 02:59:18,666 [4 ] Quartz.Core.QuartzSchedulerThread - Batch acquisition of 0 triggers
DEBUG 2019-12-14 02:59:46,115 [4 ] Quartz.Core.QuartzSchedulerThread - Batch acquisition of 1 triggers
DEBUG 2019-12-14 03:00:00,032 [4 ] Quartz.Core.QuartzSchedulerThread - Batch acquisition of 0 triggers
DEBUG 2019-12-14 03:00:00,082 [13 ] Abp.Quartz.AbpQuartzJobListener - Job TempFilesCleanUpJob executing...
DEBUG 2019-12-14 03:00:00,083 [13 ] Quartz.Core.JobRunShell - Calling Execute on job FileJobs.TemporaryFilesCleanUpJob
INFO 2019-12-14 03:00:00,085 [13 ] work.Portal.FileJobs.TempFilesCleanUpJob - Executing TemporaryFilesCleanUpJob
DEBUG 2019-12-14 03:00:06,238 [31 ] Abp.Quartz.AbpQuartzJobListener - Job TempFilesCleanUpJob sucessfully executed.
DEBUG 2019-12-14 03:00:06,334 [31 ] Quartz.Core.JobRunShell - Trigger instruction : NoInstruction
DEBUG 2019-12-**14** 03:00:26,903 [4 ] Quartz.Core.QuartzSchedulerThread - Batch acquisition of 0 triggers
DEBUG 2019-12-**16** 07:01:48,206 [1 ] Abp.Modules.AbpModuleManager - Loading Abp modules...
To me it looks like it completed our job "TempFilesCleanUpJob" successfully and then 20 seconds later it looks for another trigger and then everything shuts down. No Fatal, No errors.
Looking at the Azure app insights it shows: "An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full" - this seems to happen 250 times then nothing else happens after that.
A sample call stack of an exception is
_System.Net.Http.HttpRequestException: at System.Net.Http.ConnectHelper+<ConnectAsync>d2.MoveNext (System.Net.Http, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Threading.Tasks.ValueTask`1.getResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1+ConfiguredValueTaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Net.Http.HttpConnectionPool+<CreateConnectionAsync>d44.MoveNext (System.Net.Http, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Threading.Tasks.ValueTask`1.getResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1+ConfiguredValueTaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Net.Http.HttpConnectionPool+<WaitForCreatedConnectionAsync>d49.MoveNext (System.Net.Http, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Threading.Tasks.ValueTask`1.getResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1+ConfiguredValueTaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Net.Http.HttpConnectionPool+<SendWithRetryAsync>d39.MoveNext (System.Net.Http, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Net.Http.RedirectHandler+<SendAsync>d4.MoveNext (System.Net.Http, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Net.Http.DiagnosticsHandler+<SendAsync>d2.MoveNext (System.Net.Http, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
Inner exception System.Net.Sockets.SocketException handled at System.Net.Http.ConnectHelper+<ConnectAsync>d2.MoveNext:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Net.Http.ConnectHelper+<ConnectAsync>d2.MoveNext (System.Net.Http, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)__
Hi ismcagdas, thanks for getting back to me. I updated the CourseTrainer entity to include
public bool Equals(CourseTrainer other)
{
if (ReferenceEquals(other, null))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return CourseId.Equals(other.CourseId) && TrainerId.Equals(other.TrainerId);
}
public override int GetHashCode()
{
int hashCourseId = CourseId.GetHashCode();
int hashTrainerId = TrainerId.GetHashCode();
return hashCourseId ^ hashTrainerId;
}
With the above I was then able to use the Except keyword
private async Task UpdateCourseTrainers(Course courseInputEntity, Course savedCourse)
{
var toRemove = savedCourse.CourseTrainers.Except(courseInputEntity.CourseTrainers).ToList();
await _courseTrainerRepository.DeleteAsync(ct => toRemove.Any(t => t.TrainerId == ct.TrainerId));
var toInsert = courseInputEntity.CourseTrainers.Except(savedCourse.CourseTrainers).ToList();
foreach (var trainer in toInsert)
{
await _courseTrainerRepository.InsertAsync(trainer);
}
}
It works well now
I have a course entity which has an ICollection<CourseTrainer>
.
public class CourseTrainer : FullAuditedEntity
{
public int CourseId { get; set; }
public Course Course { get; set; }
public int TrainerId { get; set; }
public Trainer Trainer { get; set; }
public virtual bool IsSignedOff { get; set; }
public virtual DateTime? SignedOffDate { get; set; }
}
Initally I was deleting everything and then inserting everything when the user clicks save. This resulted in the record becoming IsDeleted
=1 for every save and if no changes were made to the courseTrainer then the same record would be re-inserted after. This plays havok with the audit logs and makes them less readable (because if there are a lot of trainers then every time the main course is saved there would be loads of course trainer changes)
I then tried this code which works however the IsDeleted
not being updated - instead, the record is deleted.
var toInsert = courseInputEntity.UserCourses.Except(savedCourse.UserCourses).ToList();
var toRemove = savedCourse.UserCourses.Except(courseInputEntity.UserCourses).ToList();
await _courseUserRepository.DeleteAsync(cu => toRemove.Any(t => t.Id == cu.UserId));
foreach (var trainee in toInsert)
{
await _courseUserRepository.InsertAsync(trainee);
}