EntityMappingDB 1.4.7
See the version list below for details.
dotnet add package EntityMappingDB --version 1.4.7
NuGet\Install-Package EntityMappingDB -Version 1.4.7
<PackageReference Include="EntityMappingDB" Version="1.4.7" />
paket add EntityMappingDB --version 1.4.7
#r "nuget: EntityMappingDB, 1.4.7"
// Install EntityMappingDB as a Cake Addin #addin nuget:?package=EntityMappingDB&version=1.4.7 // Install EntityMappingDB as a Cake Tool #tool nuget:?package=EntityMappingDB&version=1.4.7
EntityMappingDB
1.采用emit方法DataTable,IDataReader与实体相互转换。
2.DataTable,IDataReader转换实体: ToEntityList扩展方法
3.实体转换DataTable: FromEntityToTable扩展方法
4.如果实体转换DataTable带有特性: FromEntityToTableAttribute扩展方法
设计了三类特性ColumnType(列类型映射),DataField(列名称映射),NoColumn(没有对应的列,忽略该属性)
5.nuget
EntityMappingDB
使用
1.datatable
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("DTO", typeof(string));
dt.Rows.Add(1, "3e-6");
dt.Rows.Add(2, "5000");
List<Person> lst= dt.ToEntityList<Person>(); //转model
DataTable dd= lst.FromEntityToTable();//转回DataTable
2.IDataReader
IDataReader idr = null;
List<Person> lstm= idr.ToEntityList<Person>(); //转model
DataTable dds= lstm.FromEntityToTableAttribute<Person>(); //转回DataTable
定义:
public class Person
{
public int Id { get; set; }
[ColumnType(typeof(double))]
public decimal? DTO { get; set; }
[DataField("user")]
public string Name { get; set; }
}
说明:
1.如果程序报错:没有找到列,则说明你使用了不同的数据转model,但是这些数据不一样。这时你可以使用重载方法,定一个唯一key
2.不出意外,该项目没有升级的必要,除非emit技术有更新
程序中默认使用了缓存,datatable需要不同的名称来区分并且使用缓存
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. 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. |
-
net7.0
- System.Reflection.Emit.Lightweight (>= 4.7.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on EntityMappingDB:
Package | Downloads |
---|---|
Hikari.Integration.Entity
实体转换(采用Emit,DataTable,DataReader与List<T>相互转换) 替换其它扩展库 个人贡献,任意使用,希望保留版本和作者注释 |
GitHub repositories
This package is not used by any popular GitHub repositories.
使用说明