这是Map函数
var mapData = new Map<RxHsLocationStateTbl>().TableName("test");
mapData.Column(c => c.ContinentNameNormalized, cm => cm.WithName(nameof(RxHsLocationStateTbl.ContinentNameNormalized)));
return mapData;
如果我用这种方式Map属性,那么一切都正常吗
但是,如果我尝试使这个过程自动化,并尝试自动Map属性,那么我就得到了这个错误
public static Map<T> AutoMap<T>(List<string> exclude) where T : class
{
var tableName = typeof(T).Name.ToLower();
var mapData = new Map<T>().TableName(tableName);
foreach (var p in typeof(T).GetProperties())
{
if (!exclude.Contains(p.Name))
{
mapData.Column( c=> c.GetType().GetProperty(p.Name).Name, cm => cm.WithName(p.Name.ToLower()));
}
}
return mapData;
}
AutoMap<RxHsLocationCityTbl>(new List<string>());
错误消息:。名称引用的属性或字段不是类型
这是此列函数的内部
/// <summary>Defines options for mapping the column specified.</summary>
public Map<TPoco> Column<TProp>(
Expression<Func<TPoco, TProp>> column,
Action<ColumnMap> columnConfig)
{
if (column == null)
throw new ArgumentNullException(nameof (column));
if (columnConfig == null)
throw new ArgumentNullException(nameof (columnConfig));
MemberInfo propertyOrField = this.GetPropertyOrField<TProp>(column);
ColumnMap columnMap;
if (!this._columnMaps.TryGetValue(propertyOrField.Name, out columnMap))
{
Type memberInfoType = propertyOrField as PropertyInfo != (PropertyInfo) null ? ((PropertyInfo) propertyOrField).PropertyType : ((FieldInfo) propertyOrField).FieldType;
columnMap = new ColumnMap(propertyOrField, memberInfoType, true);
this._columnMaps[propertyOrField.Name] = columnMap;
}
columnConfig(columnMap);
return this;
}
我不明白。我做错了什么?
暂无答案!
目前还没有任何答案,快来回答吧!