Replies: 2 comments 3 replies
-
你这个用法和最初的设计思路是不一样的,实际上一个属性名称只需要设置一次就行,并不是根据实体类型去匹配,而是根据名称匹配。 比如: freeSql.GlobalFilter.Apply<IDeleted>("test", a => a.IsDeleted == false);
public interface IDeleted
{
bool IsDeleted { get; set; }
} 然后,使用该 IFreeSql 实例进行查询时,不管是否实现了这个接口,只要有这个属性字段,都会生效。 例如: public class User
{
public int Id { get; set; }
public bool IsDeleted { get; set; }
}
freeSql.Select<User>().Count().Dump(); 这时生成的SQL就是: SELECT count(1) as1
FROM "User" a
WHERE (a."IsDeleted" = 0) |
Beta Was this translation helpful? Give feedback.
2 replies
-
fsql.GlobalFilter |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
/* 使用环境
Visual Studio 2022 社区版
.Net 6
freeSQL 3.0.100
*/
两个Class均有相同的字段 IsDeleted ,
但只设置了一个过滤器如下:
fsql.GlobalFilter
.Apply<User>("test1", a => a.IsDeleted == 0) //只设置User 的,没有设置Role的过滤
如果使用 fsql.select<User, Role>innerjoin((u,r)=>u.Id == r.UserId)的情况下. 查询的SQL语句如下?
select ..... from where User.IsDeleted = 0 and Role.IsDeleted =0 //( Role的 IsDeleted 也过滤了??)
我的期望是 select ..... from where User.IsDeleted = 0。不知道是不是我用错了?
//----------------大致如下------------------
class User{
int Id
bool IsDeleted
List Roles
}
class Role{
int Id
int UserId
bool IsDeleted
IsDeleted
}
另外。如何设置同一个场景下 select, update delete 能使用不同的过滤器?即建议增加
.ApplyForSelect("test1", a => ) //可以查询所有数据
.ApplyForUpdate("test1", a => ) //只可以修改部分
.ApplyForDelete("test1", a => ) //只有管理员可删除
Beta Was this translation helpful? Give feedback.
All reactions