PredictionBuilder 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package PredictionBuilder --version 1.0.0                
NuGet\Install-Package PredictionBuilder -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PredictionBuilder" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PredictionBuilder --version 1.0.0                
#r "nuget: PredictionBuilder, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PredictionBuilder as a Cake Addin
#addin nuget:?package=PredictionBuilder&version=1.0.0

// Install PredictionBuilder as a Cake Tool
#tool nuget:?package=PredictionBuilder&version=1.0.0                

PredictionBuilder

介绍

解析实体类,生成表达式。可用于linq以及使用Expression的ORM。

软件架构

软件架构说明

安装教程
  1. nuget 搜索 PredictionBuilder 并安装
使用说明

1.定义QueryModel

//queryModel
internal class TestClass
{
   public string Id { get; set; }
   [Condition(OperatorType.Contains,ConnectType.And, "base_courses.Name", "base_video.VideoTitle")]
   public string Name1 { get; set; }
   [Condition(OperatorType.Equal, ConnectType.And, "base_courses.Infos", "base_authors.Name")]
   public string TestName { get; set; }
   public int Status { get; set; }
}

2.创建查询实体

using System;
using System.Linq;
using System.Text;
using SqlSugar;

namespace test.Model
{
    ///<summary>
    ///讲师表
    ///</summary>
    [SugarTable("base_authors")]
    public partial class base_authors
    {
           public base_authors(){


           }
           /// <summary>
           /// Desc:
           /// Default:
           /// Nullable:False
           /// </summary>           
           [SugarColumn(IsPrimaryKey=true,IsIdentity=true)]
           public int Id {get;set;}

           /// <summary>
           /// Desc:讲师姓名
           /// Default:
           /// Nullable:True
           /// </summary>           
           public string Name {get;set;}

           /// <summary>
           /// Desc:职称职位
           /// Default:
           /// Nullable:True
           /// </summary>           
           public string Position {get;set;}

           /// <summary>
           /// Desc:讲师简介
           /// Default:
           /// Nullable:True
           /// </summary>           
           public string Infos {get;set;}     
    }
}

using System;
using System.Linq;
using System.Text;
using SqlSugar;

namespace test.Model
{
    ///<summary>
    ///分类表
    ///</summary>
    [SugarTable("base_catalogs")]
    public partial class base_catalogs
    {
           public base_catalogs(){


           }
           /// <summary>
           /// Desc:
           /// Default:
           /// Nullable:False
           /// </summary>           
           [SugarColumn(IsPrimaryKey=true,IsIdentity=true)]
           public int Id {get;set;}

           /// <summary>
           /// Desc:名称
           /// Default:
           /// Nullable:True
           /// </summary>           
           public string Name {get;set;}

           /// <summary>
           /// Desc:父级Id
           /// Default:
           /// Nullable:True
           /// </summary>           
           public int? ParentId {get;set;}

           /// <summary>
           /// Desc:0正常 -1删除
           /// Default:0
           /// Nullable:True
           /// </summary>           
           public int? Status {get;set;}

    }
}

using System;
using System.Linq;
using System.Text;
using SqlSugar;

namespace test.Model
{
    ///<summary>
    ///课程和分类关联表
    ///</summary>
    [SugarTable("base_course_r_catalog")]
    public partial class base_course_r_catalog
    {
           public base_course_r_catalog(){


           }
           /// <summary>
           /// Desc:
           /// Default:
           /// Nullable:False
           /// </summary>           
           [SugarColumn(IsPrimaryKey=true,IsIdentity=true)]
           public int Id {get;set;}

           /// <summary>
           /// Desc:
           /// Default:
           /// Nullable:True
           /// </summary>           
           public int? CatalogId {get;set;}

           /// <summary>
           /// Desc:
           /// Default:
           /// Nullable:True
           /// </summary>           
           public int? CourseId {get;set;}       
           public int? Status {get;set;}


    }
}

using System;
using System.Linq;
using System.Text;
using SqlSugar;

namespace test.Model
{
    ///<summary>
    ///课程表
    ///</summary>
    [SugarTable("base_courses")]
    public partial class base_courses
    {
           public base_courses(){


           }
           /// <summary>
           /// Desc:
           /// Default:
           /// Nullable:False
           /// </summary>           
           [SugarColumn(IsPrimaryKey=true,IsIdentity=true)]
           public int Id {get;set;}

           /// <summary>
           /// Desc:课程名称
           /// Default:
           /// Nullable:True
           /// </summary>           
           public string Name {get;set;}
           /// <summary>
           /// Desc:课程简介
           /// Default:
           /// Nullable:True
           /// </summary>           
           public string Infos {get;set;}

           /// <summary>
           /// Desc:是否置顶
           /// Default:b'0'
           /// Nullable:True
           /// </summary>           
           public bool? IsTop {get;set;}

           /// <summary>
           /// Desc:状态 0正常 -1删除
           /// Default:0
           /// Nullable:True
           /// </summary>           
           public int? Status {get;set;}

    }
}

using System;
using System.Linq;
using System.Text;
using SqlSugar;

namespace test.Model
{
    ///<summary>
    ///视频和课程关联表
    ///</summary>
    [SugarTable("base_video_r_course")]
    public partial class base_video_r_course
    {
           public base_video_r_course(){


           }
           /// <summary>
           /// Desc:
           /// Default:
           /// Nullable:False
           /// </summary>           
           [SugarColumn(IsPrimaryKey=true,IsIdentity=true)]
           public int Id {get;set;}

           /// <summary>
           /// Desc:
           /// Default:
           /// Nullable:True
           /// </summary>           
           public int? VideoId {get;set;}

           /// <summary>
           /// Desc:
           /// Default:
           /// Nullable:True
           /// </summary>           
           public int? CourseId {get;set;}
           /// <summary>
           /// Desc:0 正常 -1删除
           /// Default:0
           /// Nullable:True
           /// </summary>           
           public int? Status {get;set;}

    }
}

using System;
using System.Linq;
using System.Text;
using SqlSugar;

namespace test.Model
{
    ///<summary>
    ///视频表
    ///</summary>
    [SugarTable("base_videos")]
    public partial class base_videos
    {
           public base_videos(){


           }
           /// <summary>
           /// Desc:
           /// Default:
           /// Nullable:False
           /// </summary>           
           [SugarColumn(IsPrimaryKey=true,IsIdentity=true)]
           public int Id {get;set;}

           /// <summary>
           /// Desc:正题名
           /// Default:
           /// Nullable:True
           /// </summary>           
           public string VideoTitle {get;set;}

           /// <summary>
           /// Desc:视频代码
           /// Default:
           /// Nullable:True
           /// </summary>           
           public string VideoCode {get;set;}

           /// <summary>
           /// Desc:视频排序
           /// Default:
           /// Nullable:True
           /// </summary>           
           public int? SortId {get;set;}

           /// <summary>
           /// Desc:来源于产品
           /// Default:
           /// Nullable:True
           /// </summary>           
           public string ProductFrom {get;set;}

           /// <summary>
           /// Desc:视频缩略图
           /// Default:
           /// Nullable:True
           /// </summary>           
           public string VideoImage {get;set;}

           /// <summary>
           /// Desc:文件大小(MB)
           /// Default:
           /// Nullable:True
           /// </summary>           
           public double? FileSize {get;set;}

           /// <summary>
           /// Desc:时长(秒)
           /// Default:
           /// Nullable:True
           /// </summary>           
           public double? Duration {get;set;}

           /// <summary>
           /// Desc:视频简介
           /// Default:
           /// Nullable:True
           /// </summary>           
           public string VideoInfo {get;set;}

    }
}

3.特性说明

/// <summary>
/// ctor 使用此特性声明属性的运算类型,条件之间的连接类型以及对应表达式实体的属性映射关系
/// </summary>
/// <param name="operatorType">运算类型</param>
/// <param name="connectType">和其他条件的连接类型</param>
/// <param name="mapList">映射属性(支持全称、简称和)</param>
public ConditionAttribute(OperatorType operatorType= OperatorType.Equal,ConnectType connectType=ConnectType.And, params string[] mapList)
{
       
}


/// <summary>
/// ctor 使用此特性声明如果queryModel的属性值等于哪些值,则不生成表达式
/// </summary>
/// <param name="targetType">作为哪种类型判断</param>
/// <param name="values">忽略值集合(如果集合中有一条满足条件就会跳过条件构造)</param>
public SkipBuildAttribute(Type targetType=null,params object[] values)
{

}

//支持的运算符如下:
    public enum OperatorType
    {
        /// <summary>
        /// 相等
        /// </summary>
        Equal,
        /// <summary>
        /// 不相等
        /// </summary>
        NotEqual,
        /// <summary>
        /// 小于
        /// </summary>
        LessThan,
        /// <summary>
        /// 小于等于
        /// </summary>
        LessThanOrEqual,
        /// <summary>
        /// 大于
        /// </summary>
        GreaterThan,
        /// <summary>
        /// 大于等于
        /// </summary>
        GreaterThanOrEqual,
        /// <summary>
        /// 包含
        /// </summary>
        Contains,
        /// <summary>
        /// 不包含
        /// </summary>
        NotContains,
        /// <summary>
        /// 已什么开始
        /// </summary>
        StartsWith,
        /// <summary>
        /// 不已什么开始
        /// </summary>
        NotStartsWith,
        /// <summary>
        /// 已什么结束
        /// </summary>
        EndsWith,
        /// <summary>
        /// 不已什么结束
        /// </summary>
        NotEndsWith
    }
其中从contains开始到NotEndsWith结束,要求属性必须为string类型,否则会抛出异常

2.简单应用

SqlSugarClient sqlSugarClient = new SqlSugarClient(new ConnectionConfig()
{
    ConnectionString= "Server=localhost;Database=sz_test;Uid=root;Pwd=root;charset=utf8;port=3306;SslMode = none;",
    DbType=DbType.MySql,
    IsAutoCloseConnection=true,
    AopEvents=new AopEvents()
    {
        OnLogExecuted = (sql, p) =>
        {
            Console.WriteLine(sql);
        }
    }
});
TestClass queryModel = new TestClass()
{
    Name1 = "测试",
    TestName="testName",
    Status=0
};
PredictionCreator<TestClass> creator = new PredictionCreator<TestClass>(queryModel);
var exp= creator
    .CreateBuilder<base_catalogs, base_course_r_catalog, base_courses, base_video_r_course, base_videos, base_authors>(1,null)//此参数为设置全局忽略条件,若queryModel的任意属性的值等于1或者null,则会跳过此条件的生成
    .ToExpression();
Expression<Func<base_courses, bool>> exp1 = t => t.CourseImage == "1" || t.Name == "test";
var query = sqlSugarClient.Queryable<base_catalogs, base_course_r_catalog, base_courses, base_video_r_course, base_videos, base_authors>((a, b, c, d, e, f) =>
new JoinQueryInfos(
    JoinType.Inner,a.Id==b.CatalogId,
    JoinType.Inner,b.CourseId==c.Id,
    JoinType.Inner,c.Id==d.CourseId,
    JoinType.Inner,d.VideoId==e.Id,
    JoinType.Inner,e.AuthorId==f.Id
    )
).Where(exp).ToList();

ps:最多支持Expression<Func<T-T9,bool>>个参数的表达式生成,如果需要更多,请继承 AbstractBuilder<TModel>类自行拓展

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 200 7/5/2023
1.0.3 292 6/16/2023
1.0.2 250 4/7/2023
1.0.1 206 4/4/2023
1.0.0 203 4/3/2023