Hi to all and Sorry for my bad English!
I'm doing some tests with Entity Framework Core 5 + Postgre + dynamic linq core
My DataContext is defined like this:
public class Context: DbContext {
public DbSet<Models.Anagrafica> Anagrafiche {get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql(@"Host=XYZ;Database=XYZ;Username=XYZ;Password=XYZ");
base.OnConfiguring(optionsBuilder);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Models.Anagrafica>().ToTable("Anagrafiche");
modelBuilder.Entity<Models.Anagrafica>().Property(p => p.Id)HasColumnName("id");
modelBuilder.Entity<Models.Anagrafica>().Property(p => p.RagioneSociale).HasColumnName ("ragionesociale");
modelBuilder.Entity<Models.Anagrafica>().Property(p => p.DataAttivazione).HasColumnName("dataattivazione");
base.OnModelCreating (modelBuilder);
}
}
The entity Anagrafica is defined as follows:
public class Anagrafica {
public int Id { get; set; }
public string RagioneSociale { get; set; }
public DateTime? DataAttivazione { get; set; }
}
Question: Is it possible to use the date_part function in the where?
If I run the code
var data = context.Anagrafiche.Where("date_part(\"week\", dataattivazione) = @0",1).ToList();
I get the error message
System.Linq.Dynamic.Core.Exceptions.ParseException: 'No applicable method 'date_part' exists in type 'Anagrafica''
Is it possible to use database functions and/or UDF in Dynamic Linq? If it is possible to do it what am I wrong?
Thanks!