Topre.EntityFrameworkCore.ExpressionHelp 1.0.0

dotnet add package Topre.EntityFrameworkCore.ExpressionHelp --version 1.0.0
                    
NuGet\Install-Package Topre.EntityFrameworkCore.ExpressionHelp -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="Topre.EntityFrameworkCore.ExpressionHelp" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Topre.EntityFrameworkCore.ExpressionHelp" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Topre.EntityFrameworkCore.ExpressionHelp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Topre.EntityFrameworkCore.ExpressionHelp --version 1.0.0
                    
#r "nuget: Topre.EntityFrameworkCore.ExpressionHelp, 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.
#:package Topre.EntityFrameworkCore.ExpressionHelp@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Topre.EntityFrameworkCore.ExpressionHelp&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Topre.EntityFrameworkCore.ExpressionHelp&version=1.0.0
                    
Install as a Cake Tool

此库主要用于在使用EntityFramework查询时做一些表达式相关扩展

  • 我的项目中,平常都会将EF的一些查询定义出来,如下所示:
public static Expression<Func<EquipmentInfo, SimpleEquipmentInfo>> SimpleEquipmentInfoExpression = s => new SimpleEquipmentInfo
        {
            Id = s.Id,
            Name = s.Name
        };
  • 当我进行查询时:
_context.EquipmentInfo.Select(SimpleEquipmentInfoExpression).ToList();
  • 我的当前做法是这样,可以复用一些表达式,不需要每次都写同样的表达式。
  • 但是我又遇到了其他的问题,假设我想扩展一个属性,如下所示:
public class InfoExtCategoryName : SimpleEquipmentInfo
    {
        public string CategoryName { get; set; }
    }
  • 此时我必须再写一个表达式,如下:
public static Expression<Func<EquipmentInfo, InfoExtCategoryName>> InfoExtCategoryName
            = s => new InfoExtCategoryName
            {
                Id = s.Id,
                Name = s.Name,
                CategoryName = s.EquipmentCategoryNav.Name
            };
  • 这样就造成了重复的代码,于是我就打算扩展一个Merge方法来解决这个问题。
  • 使用方法:
  1. 引入命名空间
using EntityFrameworkCore.ExpressionHelp;
  1. 调用扩展方法
public static Expression<Func<EquipmentInfo, InfoExtCategoryName>> InfoExtCategoryNameByMerge = 
SimpleEquipmentInfoExpression.Merge(s => new InfoExtCategoryName { CategoryName = s.EquipmentCategoryNav.Name});
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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • 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.0 375 1/30/2021