v0.0.13 #4 - 修复和丰富 ICodeFirst.ConfigEntity 方法;

- 增加 FreeSql.Extensions.EFCoreModelBuilder 扩展库,现实与 EFCore 实体共存;
- 增加 FreeSql.RESTful.Demo 示例项目;
This commit is contained in:
28810
2019-02-14 19:07:52 +08:00
parent 45bc234160
commit 488a6edd4d
18 changed files with 190 additions and 22 deletions

View File

@ -1,7 +1,7 @@
using System;
namespace FreeSql.DataAnnotations {
public class ColumnFluent<T> {
public class ColumnFluent {
public ColumnFluent(ColumnAttribute column) {
_column = column;
@ -11,21 +11,21 @@ namespace FreeSql.DataAnnotations {
/// <summary>
/// 数据库列名
/// </summary>
public ColumnFluent<T> Name(string value) {
public ColumnFluent Name(string value) {
_column.Name = value;
return this;
}
/// <summary>
/// 指定数据库旧的列名修改实体属性命名时同时设置此参数为修改之前的值CodeFirst才可以正确修改数据库字段否则将视为【新增字段】
/// </summary>
public ColumnFluent<T> OldName(string value) {
public ColumnFluent OldName(string value) {
_column.OldName = value;
return this;
}
/// <summary>
/// 数据库类型,如: varchar(255)
/// </summary>
public ColumnFluent<T> DbType(string value) {
public ColumnFluent DbType(string value) {
_column.DbType = value;
return this;
}
@ -33,20 +33,20 @@ namespace FreeSql.DataAnnotations {
/// <summary>
/// 主键
/// </summary>
public ColumnFluent<T> IsPrimary(bool value) {
public ColumnFluent IsPrimary(bool value) {
_column.IsPrimary = value;
return this;
}
/// 自增标识
/// </summary>
public ColumnFluent<T> IsIdentity(bool value) {
public ColumnFluent IsIdentity(bool value) {
_column.IsIdentity = value;
return this;
}
/// <summary>
/// 是否可DBNull
/// </summary>
public ColumnFluent<T> IsNullable(bool value) {
public ColumnFluent IsNullable(bool value) {
_column.IsNullable = value;
return this;
}

View File

@ -17,6 +17,6 @@ namespace FreeSql.DataAnnotations {
/// </summary>
public string SelectFilter { get; set; }
internal ConcurrentDictionary<string, ColumnAttribute> _columns => new ConcurrentDictionary<string, ColumnAttribute>(StringComparer.CurrentCultureIgnoreCase);
internal ConcurrentDictionary<string, ColumnAttribute> _columns { get; } = new ConcurrentDictionary<string, ColumnAttribute>(StringComparer.CurrentCultureIgnoreCase);
}
}

View File

@ -1,9 +1,51 @@
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace FreeSql.DataAnnotations {
public class TableFluent {
public TableFluent(Type entityType, TableAttribute table) {
_entityType = entityType;
_properties = _entityType.GetProperties().ToDictionary(a => a.Name, a => a, StringComparer.CurrentCultureIgnoreCase);
_table = table;
}
Type _entityType;
Dictionary<string, PropertyInfo> _properties;
TableAttribute _table;
/// <summary>
/// 数据库表名
/// </summary>
public TableFluent Name(string value) {
_table.Name = value;
return this;
}
/// <summary>
/// 指定数据库旧的表名修改实体命名时同时设置此参数为修改之前的值CodeFirst才可以正确修改数据库表否则将视为【创建新表】
/// </summary>
public TableFluent OldName(string value) {
_table.OldName = value;
return this;
}
/// <summary>
/// 查询过滤SQL实现类似 a.IsDeleted = 1 功能
/// </summary>
public TableFluent SelectFilter(string value) {
_table.SelectFilter = value;
return this;
}
public ColumnFluent Property(string proto) {
if (_properties.ContainsKey(proto) == false) throw new KeyNotFoundException($"找不到属性名 {proto}");
var col = _table._columns.GetOrAdd(proto, name => new ColumnAttribute { Name = proto });
return new ColumnFluent(col);
}
}
public class TableFluent<T> {
public TableFluent(TableAttribute table) {
@ -33,11 +75,11 @@ namespace FreeSql.DataAnnotations {
return this;
}
public ColumnFluent<TProto> Property<TProto>(Expression<Func<T, TProto>> column) {
public ColumnFluent Property<TProto>(Expression<Func<T, TProto>> column) {
var proto = (column.Body as MemberExpression)?.Member;
if (proto == null) throw new FormatException($"错误的表达式格式 {column}");
var col = _table._columns.GetOrAdd(proto.Name, name => new ColumnAttribute { Name = proto.Name });
return new ColumnFluent<TProto>(col);
return new ColumnFluent(col);
}
}
}