-
-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
With UseParameterizedNamesInDynamicQuery, can't compare DateTimeOffset with String #645
Comments
@neilbgr The reason why this doesn't work is because the string value is wrapped in a I'll take a look if this can be fixed, however I think it's difficult. |
@neilbgr |
// Dynamic LINQ - neilbgr
// @nuget: System.Linq.Dynamic.Core
// @nuget: Z.EntityFramework.Classic
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Entity;
using System.Linq.Dynamic.Core;
public class Program
{
public static void Main()
{
GenerateData();
var context = new EntityContext();
var query1 = context.Customers
.Include(c => c.Location)
.Where("LastContact = \"2022-11-16\"");
query1.Dump();
query1 = context.Customers
.Include(c => c.Location)
.Where("Location.UpdateAt = \"2022-11-16\"");
query1.Dump();
var config = new ParsingConfig
{
UseParameterizedNamesInDynamicQuery = true
};
try
{
var query2 = context.Customers
.Include(c => c.Location)
.Where(config, "LastContact = \"2022-11-16\"");
query2.Dump();
}
catch (Exception ex)
{
ex.Message.Dump();
}
try
{
var query3 = context.Customers
.Include(c => c.Location)
.Where(config, "Location.UpdateAt = \"2022-11-16\"");
query3.Dump();
}
catch (Exception ex)
{
ex.Message.Dump();
}
}
public static void GenerateData()
{
var list = new List<Customer>();
list.Add(new Customer()
{
Name = "Terri Lee Duffy",
CompanyName = "ABC",
City = "Paris",
Phone = "333-444444",
Location = new Location() { Name = "test" },
LastContact = DateTimeOffset.Parse("2022-11-14")
});
list.Add(new Customer()
{
Name = "Garry Moore",
CompanyName = "ABC",
City = "Paris",
Phone = "54654-444444",
Location = new Location() { Name = "ohter test", UpdateAt = DateTimeOffset.Parse("2022-11-16") },
LastContact = DateTimeOffset.Parse("2022-11-16")
});
using (var context = new EntityContext())
{
context.Customers.AddRange(list);
context.BulkSaveChanges();
}
}
public class EntityContext : DbContext
{
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
{
}
public DbSet<Customer> Customers { get; set; }
public DbSet<Location> Locations { get; set; }
}
public class Customer
{
public int CustomerID { get; set; }
public string Name { get; set; }
public string CompanyName { get; set; }
public string City { get; set; }
public string Phone { get; set; }
public Location Location { get; set; }
public DateTimeOffset? LastContact { get; set; }
}
public class Location
{
public int LocationID { get; set; }
public string Name { get; set; }
public DateTimeOffset UpdateAt { get; set; }
}
} |
With result:
|
Great! (😅 #666 PR of the beast! 😈) |
1. Description
When
UseParameterizedNamesInDynamicQuery = true
in config (for best perfs), can not compareDateTimeOffset?
withString
anymore (evenDateTimeOffset
).2. Exception
3. Fiddle or Project
https://dotnetfiddle.net/UGmC2g
An idea?
Thanks.
The text was updated successfully, but these errors were encountered: