- 增加 FreeSql.Extensions.JsonMap FluentApi 扩展方法;#279

This commit is contained in:
28810
2020-04-19 00:09:24 +08:00
parent c0d29b3906
commit a0e18b1a68
6 changed files with 70 additions and 71 deletions

View File

@ -1,16 +1,22 @@
using System;
using System.Collections.Generic;
using System.Reflection;
namespace FreeSql.DataAnnotations
{
public class ColumnFluent
{
public ColumnFluent(ColumnAttribute column)
public ColumnFluent(ColumnAttribute column, PropertyInfo property, Type entityType)
{
_column = column;
_property = property;
_entityType = entityType;
}
ColumnAttribute _column;
public ColumnAttribute _column;
public PropertyInfo _property;
public Type _entityType;
/// <summary>
/// 数据库列名
/// </summary>

View File

@ -47,9 +47,9 @@ namespace FreeSql.DataAnnotations
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);
if (_properties.TryGetValue(proto, out var tryProto) == false) throw new KeyNotFoundException($"找不到属性名 {proto}");
var col = _table._columns.GetOrAdd(tryProto.Name, name => new ColumnAttribute { Name = proto });
return new ColumnFluent(col, tryProto, _entityType);
}
/// <summary>
@ -131,7 +131,7 @@ namespace FreeSql.DataAnnotations
{
if (_properties.TryGetValue(proto, out var tryProto) == false) throw new KeyNotFoundException($"找不到属性名 {proto}");
var col = _table._columns.GetOrAdd(tryProto.Name, name => new ColumnAttribute { Name = proto });
return new ColumnFluent(col);
return new ColumnFluent(col, tryProto, typeof(T));
}
/// <summary>