-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Translation of ISNUMERIC under SF.Functions #23114
Comments
Until this is done in the provider, you can map this as a DbFunction yourself - see the code sample below. Using DbFunctionawait using var ctx = new BlogContext();
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();
_ = await ctx.Blogs.Where(b => ctx.IsNumeric(b.Name)).ToListAsync();
public class BlogContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
static ILoggerFactory ContextLoggerFactory
=> LoggerFactory.Create(b => b.AddConsole().AddFilter("", LogLevel.Information));
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(@"Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0")
.EnableSensitiveDataLogging()
.UseLoggerFactory(ContextLoggerFactory);
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDbFunction(IsNumericMethodInfo)
.HasName("ISNUMERIC")
.IsBuiltIn();
}
private static readonly MethodInfo IsNumericMethodInfo = typeof(BlogContext)
.GetRuntimeMethod(nameof(IsNumeric), new[] { typeof(string) });
public bool IsNumeric(string s) => throw new NotSupportedException();
}
public class Blog
{
public int Id { get; set; }
public string Name { get; set; }
} |
@smitpatel @maumar note that with the above I get: SELECT [b].[Id], [b].[Name]
FROM [Blogs] AS [b]
WHERE ISNUMERIC([b].[Name]) = CAST(1 AS bit) The |
IsNumeric returns int in T-Sql. |
Ah weird... |
Note from triage: If there is an appropriate BCL method to translate, then we should do that instead. However, I don't think we have identified such a method at this time. |
Co-authored-by: HuyLuong <[email protected]> Resolves #23114
Design question for @dotnet/efteam |
@smitpatel Did you get an answer on this? |
No. I will bring it to next design meeting. |
Design meeting decision: We decided to keep this as |
Hello,
Could you please add a translation to SQL Server's ISNUMERIC under EF.Functions ?
Thank you.
Best regards.
Originally posted by @evannah in #23078 (comment)
The text was updated successfully, but these errors were encountered: