-
Notifications
You must be signed in to change notification settings - Fork 455
Method handler
shuxin edited this page Oct 31, 2023
·
3 revisions
框架并未对数据库所有的特性做支持,有些函数或语法得需要自己翻译,Chloe.ORM 提供了相应的支持接口,参考如下:
例:对如下 StringLike 方法解析
public static class DbFunctions
{
public static bool StringLike(this string str, string value)
{
return str.Contains(value);
}
}
1. 添加一个继承 IMethodHandler 的类,并实现 CanProcess 和 Process 两个方法
public class PostgreSQL_StringLike_MethodHandler : IMethodHandler
{
/// <summary>
/// 判断是否可以解析传入的方法。
/// </summary>
/// <param name="exp"></param>
/// <returns></returns>
public bool CanProcess(DbMethodCallExpression exp)
{
if (exp.Method.DeclaringType != typeof(DbFunctions))
return false;
return true;
}
/// <summary>
/// 解析传入的方法。
/// </summary>
/// <param name="exp"></param>
/// <param name="generator"></param>
public void Process(DbMethodCallExpression exp, SqlGeneratorBase generator)
{
exp.Arguments[0].Accept(generator);
generator.SqlBuilder.Append(" LIKE '%' || ");
exp.Arguments[1].Accept(generator);
generator.SqlBuilder.Append(" || '%'");
}
}
2. 在程序启动时配置解析器
PostgreSQLContext.SetMethodHandler("StringLike", new PostgreSQL_StringLike_MethodHandler());
//其他库请调用其他库上下文对象下的 SetMethodHandler 方法设置。
3. 在 lambda 表达式中使用
query.Where(a => DbFunctions.StringLike(a.Name, "Chloe")}).ToList();
/*
* SELECT * FROM "person" AS "person" WHERE "person"."name" LIKE '%' || N'Chloe' || '%'
*/
更多用法参考 https://github.com/shuxinqin/Chloe/tree/master/src/ChloeDemo 。
熬夜的时候容易引起脱发,熬夜时人的免疫力会下降,还会引起内分泌的变化,导致皮脂分泌增多,这些因素都不利于头发的生长,有可能引起脱发。如果出现熬夜脱发的情况,需要及时纠正日常的生活习惯,合理安排休息时间,早睡早起,适当的锻炼身体,多进食优质的蛋白质,增强身体的抵抗力,促进头发的生长。
发量有限,远离996!!!