-
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
Configured DbFunctionParameter doesn't impact query parameter mapping #25980
Comments
Also try |
Hi @roji we are storing date properties as integer in database, in this case we have valueconverters. When we want to call database function that concats date and time i need to set TypeMapping as I understand? But how to get RelationalTypeMapping from "DateConverter"s modelBuilder.HasDbFunction(...).HasParameter("startDate").Metadata.TypeMapping = ? With NHibernate its easy as MappedAs(SqlNumberDateTimeyyyyMMddHHmmss.Type) return (from online in ISession.Query<Transaction>().Where(predicate)
where online.TxnDefinition.IsFinancial &&
online.TxnResponseCodeDefinition.IsApproved &&
online.TxnSettle == TxnSettle.Settled.GetKey() &&
online.TxnStt == TxnStat.Normal.GetKey() &&
online.RequestDateYYYYMMDD.ToDateTime(online.F12, 6) <= DateTime.Now.AddSeconds(-30).MappedAs(SqlNumberDateTimeyyyyMMddHHmmss.Type)
select online.Guid)
.AsEnumerable(); public static DateTime ToDateTime(this DateTime currentDate, int currentTime, int paddingLength = 6) => throw new NotSupportedException();
public class DateConverter : ValueConverter<DateTime, int>
{
protected static readonly string Format = "yyyyMMdd";
public static readonly DateTime DefaultDate = new(1900, 1, 1, 0, 0, 0, 0);
public DateConverter() :
base(v => int.Parse(v.ToString(Format)),
v => DateTime.ParseExact(v.ToString(), Format, CultureInfo.InvariantCulture, DateTimeStyles.None))
{
}
} CREATE OR REPLACE FUNCTION to_date_time(currentdate numeric, currenttime numeric, paddinglength integer)
RETURNS text
LANGUAGE plpgsql
AS $function$
declare
begin
return CAST(CAST(currentdate AS text)||LPAD(CAST(currenttime AS text),paddinglength,'0') as numeric);
end;
$function$
; |
I use EntityFrameworkCore.Projectables library BirthDate in database stored as YYYYMMDD, BirthTime storead as hhmmss projectable succesfully concats these two properties with unnecessary coalesce operator, at least its working. CAST((a.birth_date::text || COALESCE(lpad(a.birth_time::text, 6, '0'), '')) AS bigint) >= @__ToLongDateTime_0 |
When configuring a function's parameter's mapping in the model:
My expectation was that this would impact the mapping used in the query pipeline (i.e. when a constant/parameter is given), but that does not seem to be the case.
Repro
The above generates the SQL
[dbo].[Foo](N'true')
, whereas I'd expect it to generate[dbo].[Foo](CAST(1 AS bit))
(or possibly throw).The text was updated successfully, but these errors were encountered: