WhereCascade 多表查詢時很是方便,有了它能夠很輕鬆的完成類型軟刪除,租戶條件的功能。html
IFreeSql fsql = new FreeSql.FreeSqlBuilder() .UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10") .Build(); [Table(Name = "tb_topic")] class Topic { [Column(IsIdentity = true, IsPrimary = true)] public int Id { get; set; } public int Clicks { get; set; } public int TestTypeInfoGuid { get; set; } public TestTypeInfo Type { get; set; } public string Title { get; set; } public DateTime CreateTime { get; set; } } class TestTypeInfo { public int Guid { get; set; } public int ParentId { get; set; } public TestTypeParentInfo Parent { get; set; } public string Name { get; set; } public List<Topic> Topics { get; set; } } class TestTypeParentInfo { public int Id { get; set; } public string Name { get; set; } } ISelect<Topic> select => fsql.Select<Topic>();
多表查詢時,像isdeleted每一個表都給條件,挺麻煩的。WhereCascade使用後生成sql時,全部表都附上這個條件。sql
如:ui
fsql.Select<t1>() .LeftJoin<t2>(...) .WhereCascade(x => x.IsDeleted == false) .ToList();
獲得的 SQL:code
SELECT ... FROM t1 LEFT JOIN t2 on ... AND (t2.IsDeleted = 0) WHERE t1.IsDeleted = 0
其中的實體可附加表達式時才生效,支持子表查詢。單次查詢使用的表數目越多收益越大。htm
可應用範圍:blog
暫時不支持【延時屬性】的廣播;事務
此功能和【過濾器】不一樣,用於單次多表查詢條件的傳播;get
(一)入門string
(二十)多表查詢 WhereCascade