/// <summary> /// 指定忽略字段 /// </summary> /// <typeparam name="T">表达式对应类型</typeparam> /// <param name="convention">模型约定</param> /// <param name="expression">Lambda表达式</param> /// <returns></returns> public static ModelConvention Ignore <T>(this ModelConvention convention, Expression <Func <T, object> > expression) where T : class { var property = ReadExpression(expression); convention.Properties(x => x == property).Ignore(); return(convention); }
public DapperDatabaseOptions() { _convention = new Lazy <ModelConvention>(() => { ModelConvention c = new ModelConvention(); this.ConventionConfigure?.Invoke(c); return(c); }, false); }
/// <summary> /// 构造函数 /// </summary> /// <param name="entityType"></param> /// <param name="typeConvention"></param> /// <param name="modelConvention"></param> public DapperMetadata(Type entityType, TypeConvention typeConvention, ModelConvention modelConvention) { Guard.ArgumentNotNull(entityType, nameof(entityType)); EntityType = entityType; var metadatas = from prop in entityType.GetProperties(BindingFlags.Public | BindingFlags.Instance) where prop.CanRead && prop.CanWrite && CheckFieldType(prop.PropertyType) let convention = modelConvention.PropertyConventions.FirstOrDefault(x => x.Filter(prop)) select convention != null ? new DapperFieldMetadata(prop, convention) : new DapperFieldMetadata(prop); Fields = metadatas.ToList(); TableName = MappingStrategyParser.Parse(entityType.Name); if (typeConvention.Filter(entityType)) { ReadingConnectionName = typeConvention.DbReadingConnectionName; WritingConnectionName = typeConvention.DbWritingConnectionName; } }