"Could not parse Expression '...: The Given Arguments Did not match the expected Arguments"

Asked

Viewed 54 times

1

I am using the Compiledqueries Feature of the framewok core 2.0 Entity but Even though it does not Give syntax error, when the program is running, I get this Exception:

Could not parse Expression 'value (Microsoft.EntityFrameworkCore.Query.Internal.Entityqueryable`1 [Taskmanager.Entities.Entitiesdb.USER]) Asnotracking (). Where (__ conditions)': The Given Arguments Did not match the expected Arguments: Object of type 'System.Linq.Expressions.Typedparameterexpression' can not be converted to type 'System.Linq.Expressions.Lambdaexpression'.

I have no idea what it is. I Need help.

Here is the source code of my Repository which displays this error:

/// <summary>
/// Query of user
/// </summary>
/// <param name="_context">context</param>
/// <param name="conditions">conditions for clause "Where"</param>
/// <returns>first task that meets the conditions or null </returns>
private static Func<Context, Func<USER, bool>, Task<UserResponseDTO>> _getUser = EF.CompileAsyncQuery 
(
   (Context _context, Func<USER, bool> conditions) =>
      (conditions == null)? 
          _context.USER.Select(user =>
              new UserResponseDTO {
                NAME = user.NAME,
                EMAIL = user.EMAIL,
                SEQUSER = user.SEQUSER,
                DATEREGISTER = user.DATEREGISTER
              }
           ).AsNoTracking().FirstOrDefault ()
      :                                        
          _context.USER.AsNoTracking()
          .Where(conditions).Select(user =>
              new UserResponseDTO {
                NAME = user.NAME,
                EMAIL = user.EMAIL,
                SEQUSER = user.SEQUSER,
                DATEREGISTER = user.DATEREGISTER
              }
           ).FirstOrDefault ()
);

My class that Implements Dbcontext :

public class Context: DbContext
{
    public Context(DbContextOptions<Context> options): base(options){ }
    public virtual DbSet<USER> USER { get; set; }
    public virtual DbSet<TASK> TASK { get; set; }
    protected override void OnModelCreating(ModelBuilder modelBuilder){
        #region Sequences

        modelBuilder.HasSequence<long> 
        ("S_SEQUSER").StartsAt(1).HasMin(1);
        modelBuilder.HasSequence<long> 
        ("S_SEQTASK").StartsAt(1).HasMin(1);                   

        #endregion

        #region propeties Mapping
        modelBuilder.Entity<USER>()
            .Property(u => u.SEQUSER)                
            .HasDefaultValueSql(" nextval('\"S_SEQUSER\"') ");

        modelBuilder.Entity<TASK>()
           .Property(u => u.SEQTASK)            
           .HasDefaultValueSql(" nextval('\"S_SEQTASK\"') ");

        modelBuilder.Entity<USER>()
        .HasMany(u => u.TASK)
        .WithOne(u => u.USER);   
        #endregion        

        base.OnModelCreating(modelBuilder);
    }
}

my database Entity:

/// <summary>
/// query user
/// </summary>
[Table(@"USER")]
public class USER
{
    #region Properties
    /// <summary>
    /// sequence of user
    /// </summary>
    /// <value></value>
    [Key()]
    [Column(@"SEQUSER")]
    public virtual long SEQUSER { get; set; }

    /// <summary>
    /// email of user
    /// </summary>
    /// <value></value>
    [Required]
    [StringLength(120)]
    [Column(@"EMAIL")]
    public virtual string EMAIL { get; set; }

    /// <summary>
    /// password of user
    /// </summary>
    /// <value></value>
    [Required]
    [StringLength(15)]
    [Column(@"PASSWORD")]
    public virtual string PASSWORD { get; set; }

    /// <summary>
    /// name of user
    /// </summary>
    /// <value></value>
    [Required]
    [StringLength(120)]
    [Column(@"NAME")]
    public virtual string NAME { get; set; }        

    /// <summary>
    /// date of user was registered
    /// </summary>
    /// <value></value>
    [Column(@"DATEREGISTER")]
    public virtual DateTime DATEREGISTER { get; set; }

    /// <summary>
    /// last acess of user in application
    /// </summary>
    /// <value></value>
    [Column(@"LASTACESS")]
    public virtual DateTime LASTACESS { get; set; }

    /// <summary>
    /// list of task 
    /// </summary>
    /// <value></value>
    [InverseProperty("USER")]
    public virtual List<TASK> TASK { get; set; }

    #endregion    
}

Could someone Give me a hand in this?

  • Hello @Samuel. Your question (including the title) should be made in English. Take the opportunity to Tour to better understand how the website.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.