Closed aloksharma1 closed 1 month ago
If you add .ToLinqToDB()
in projection? It has no sense.
ok, i removed it from projection but its the same .ToLinqToDB().ToList()
the error didnt go away i am upgrading my project to latest dotnet it is working ok in net 5 version.
public new bool? IsActive { get; set; } = true;
How it is mapped to database?
using fluent api of ef core 7.0.10
builder.Property(e => e.IsActive).IsRequired(false).HasDefaultValueSql("1");
the thing is its working ok if i remove ToLinqToDB.
found it, in some place it was overriden by .IsRequired() it worked for ef core but gave error in linqtodb conversion, looks like linq2db is more strict.
Post your model classes. Base class and this one withIsActive
. Will check what happened.
Hi, sorry for late reply have been stuck in this project upgrade so hardly getting any time, the problem still persists as i have explained above, here is the model classes:
public abstract class BaseEntity : Framework.Domain.Common.BaseEntity, IEquatable<BaseEntity>, IBaseEntity<long>
{
[Key]
public new virtual long Id { get; set; }
public new bool? IsActive { get; set; } = true;
public new DateTimeOffset? DateCreated { get; set; } = DateTimeOffset.UtcNow;
public new DateTimeOffset? DateModified { get; set; } = DateTimeOffset.UtcNow;
[NotMapped]
public virtual Constants.ActionType? ActionType { get; set; } = Constants.ActionType.Create;
[NotMapped]
public override bool IsModified { get; set; }
public bool Equals([AllowNull] BaseEntity other)
{
return Equals(other);
}
}
public abstract class GeneralEntity : BaseEntity, IEquatable<GeneralEntity>
{
public virtual long SiteId { get; set; }
public bool Equals([AllowNull] GeneralEntity other)
{
return Equals(other);
}
}
public class PageProperties : GeneralEntity
{
//to use bigger range on created records
public virtual new Guid Id { get; set; } = Guid.NewGuid();
//[StringLength(500)]
//[Required]
public virtual string? PageName { get; set; }
//additional properties redacted
public virtual RecordStatus RecordStatus { get; set; }
public virtual DateTimeOffset LastRequested { get; set; } = DateTimeOffset.UtcNow;
}
}
public class Pages : PageProperties
{
public DateTimeOffset? PublishDate { get; set; }
}
my code is divide in many different modules, so there is a lot of abstract classes. Anyways the issue is due to nullable type handling that much i can tell.
Please add BaseEntity
base entity is same as the above base entity just without nulls and extra cluttering
public abstract class BaseEntity : IBaseEntity<Guid>
{
public virtual Guid Id { get; set; }
public DateTimeOffset DateCreated { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset DateModified { get; set; } = DateTimeOffset.UtcNow;
public bool IsActive { get; set; } = true;
public bool IsModified { get; set; } =false;
}
hi, were you able to find any solution to this issue? i am mostly stuck with union queries that were working previously like this one error it works individually but when I union it with some other table I get this error
Sequence 'value(LinqToDB.EntityFrameworkCore.LinqToDBForEFToolsDataConnection).GetTable().TagQuery("query called for Images") .Where(pi => ((pi.Id == value(LinqToDB.EntityFrameworkCore.LinqToDBForEFToolsDataConnection).GetTable() .TagQuery("query called for BlogPostImages").Where(pim => ((pim.IsActive == Convert(True, Nullable`1)) AndAlso (pim.BlogId == x.Id))).Select(pim => pim.PostImageId).FirstOrDefault()) AndAlso pi.isPublished)) .OrderBy(pi => pi.SortOrder) .Select(pi => new SearchImages() {ImagePath = pi.ImagePath, ImageAltText = pi.ImageAltText, SortOrder = pi.SortOrder, Id = pi.Id}).ToList()' cannot be converted to SQL.
Note: Using AsSplitQuery made it work, i didnt had to do that before as i am simply copying old code from dotnet 5 to 7.
Hi, sorry for late reply have been stuck in this project upgrade so hardly getting any time, the problem still persists as i have explained above, here is the model classes:
public abstract class BaseEntity : Framework.Domain.Common.BaseEntity, IEquatable<BaseEntity>, IBaseEntity<long> { [Key] public new virtual long Id { get; set; } public new bool? IsActive { get; set; } = true; public new DateTimeOffset? DateCreated { get; set; } = DateTimeOffset.UtcNow; public new DateTimeOffset? DateModified { get; set; } = DateTimeOffset.UtcNow; [NotMapped] public virtual Constants.ActionType? ActionType { get; set; } = Constants.ActionType.Create; [NotMapped] public override bool IsModified { get; set; } public bool Equals([AllowNull] BaseEntity other) { return Equals(other); } }
public abstract class GeneralEntity : BaseEntity, IEquatable<GeneralEntity> { public virtual long SiteId { get; set; } public bool Equals([AllowNull] GeneralEntity other) { return Equals(other); } }
public class PageProperties : GeneralEntity { //to use bigger range on created records public virtual new Guid Id { get; set; } = Guid.NewGuid(); //[StringLength(500)] //[Required] public virtual string? PageName { get; set; } //additional properties redacted public virtual RecordStatus RecordStatus { get; set; } public virtual DateTimeOffset LastRequested { get; set; } = DateTimeOffset.UtcNow; } }
public class Pages : PageProperties { public DateTimeOffset? PublishDate { get; set; } }
my code is divide in many different modules, so there is a lot of abstract classes. Anyways the issue is due to nullable type handling that much i can tell.
Why are you redefining those properties, and why are they virtual in the first place? Do you realize what new virtual
does?
Hi, sorry for late reply have been stuck in this project upgrade so hardly getting any time, the problem still persists as i have explained above, here is the model classes:
public abstract class BaseEntity : Framework.Domain.Common.BaseEntity, IEquatable<BaseEntity>, IBaseEntity<long> { [Key] public new virtual long Id { get; set; } public new bool? IsActive { get; set; } = true; public new DateTimeOffset? DateCreated { get; set; } = DateTimeOffset.UtcNow; public new DateTimeOffset? DateModified { get; set; } = DateTimeOffset.UtcNow; [NotMapped] public virtual Constants.ActionType? ActionType { get; set; } = Constants.ActionType.Create; [NotMapped] public override bool IsModified { get; set; } public bool Equals([AllowNull] BaseEntity other) { return Equals(other); } }
public abstract class GeneralEntity : BaseEntity, IEquatable<GeneralEntity> { public virtual long SiteId { get; set; } public bool Equals([AllowNull] GeneralEntity other) { return Equals(other); } }
public class PageProperties : GeneralEntity { //to use bigger range on created records public virtual new Guid Id { get; set; } = Guid.NewGuid(); //[StringLength(500)] //[Required] public virtual string? PageName { get; set; } //additional properties redacted public virtual RecordStatus RecordStatus { get; set; } public virtual DateTimeOffset LastRequested { get; set; } = DateTimeOffset.UtcNow; } }
public class Pages : PageProperties { public DateTimeOffset? PublishDate { get; set; } }
my code is divide in many different modules, so there is a lot of abstract classes. Anyways the issue is due to nullable type handling that much i can tell.
Why are you redefining those properties, and why are they virtual in the first place? Do you realize what
new virtual
does?
i am using these base classes in other places too, where i have to override these properties (old database structure is not same for all tables some are using int some guid some long, it a pain but it is what it is).
It is hard to say anything when half of code, required to run query is missing. Please reopen if you can provide isolated example with all code parts: query, mappings, entities
hi i think this is a possible bug, can you check this query:
but if i add :
i am getting following error:
Expression 'x.IsActive' is not a Field.
its defined in model as
public new bool? IsActive { get; set; } = true;
full stacktrace:
please check linq2db.efcore version 7.5.0