/// <summary> /// 声明一个引用实体属性。 /// </summary> /// <typeparam name="TRefEntity"></typeparam> /// <param name="propertyExp">指向引用实体属性的表达式。</param> /// <param name="args">引用实体属性相应的参数对象。</param> /// <returns></returns> public static RefEntityProperty <TRefEntity> RegisterRef <TRefEntity>(Expression <Func <TEntity, TRefEntity> > propertyExp, RegisterRefArgs args) where TRefEntity : Entity { if (args == null) { throw new ArgumentNullException("args"); } if (args.RefIdProperty == null) { throw new ArgumentNullException("args.RefIdProperty", "必须指定引用 Id 属性,将为其建立关联。"); } //简单地,直接把 Args 作为 defaultMeta var defaultMeta = args; var property = new RefEntityProperty <TRefEntity>(typeof(TEntity), GetPropertyName(propertyExp), defaultMeta) { RefIdProperty = args.RefIdProperty, Loader = args.Loader }; //默认只从服务端序列化到客户端。 (defaultMeta as PropertyMetadata <Entity>).Serializable = args.Serializable.GetValueOrDefault(RafyEnvironment.IsOnServer()); ManagedPropertyRepository.Instance.RegisterProperty(property); return(property); }
/// <summary> /// 为某个实体类型重写指定引用属性对应的元数据。 /// </summary> /// <typeparam name="TRefEntity">The type of the reference entity.</typeparam> /// <typeparam name="TMeta">The type of the meta.</typeparam> /// <param name="property">The property.</param> /// <param name="args">The arguments.</param> /// <param name="overrideValues">The override values.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">args</exception> /// <exception cref="System.InvalidOperationException">不支持重写 Loader 属性。</exception> public static RefEntityProperty <TRefEntity> OverrideRefMeta <TRefEntity, TMeta>( RefEntityProperty <TRefEntity> property, TMeta args, Action <TMeta> overrideValues ) where TRefEntity : Entity where TMeta : RegisterRefArgs { if (property == null) { throw new ArgumentNullException("property"); } if (args == null) { throw new ArgumentNullException("args"); } if (overrideValues == null) { throw new ArgumentNullException("overrideValues"); } if (args.Loader != null) { throw new InvalidOperationException("不支持重写 Loader 属性。"); } //简单地,直接把 Args 作为 meta property.OverrideMeta(typeof(TEntity), args, m => { //默认只从服务端序列化到客户端。 (m as PropertyMetadata <Entity>).Serializable = m.Serializable.GetValueOrDefault(RafyEnvironment.IsOnServer()); overrideValues(m); }); return(property); }
/// <summary> /// 扩展一个引用实体属性。 /// </summary> /// <typeparam name="TRefEntity"></typeparam> /// <param name="propertyName">实体属性的名称。</param> /// <param name="declareType">声明此属性的类型。</param> /// <param name="refIdProperty">对应的引用 Id 属性,将为其建立关联。</param> /// <returns></returns> public static RefEntityProperty <TRefEntity> RegisterRefExtension <TRefEntity>(string propertyName, Type declareType, IRefIdProperty refIdProperty) where TRefEntity : Entity { if (refIdProperty == null) { throw new ArgumentNullException("refIdProperty", "必须指定引用 Id 属性,将为其建立关联。"); } var defaultMeta = new PropertyMetadata <Entity>(); var property = new RefEntityProperty <TRefEntity>(typeof(TEntity), declareType, propertyName, defaultMeta) { RefIdProperty = refIdProperty }; //默认只从服务端序列化到客户端。 defaultMeta.Serializable = RafyEnvironment.IsOnServer(); ManagedPropertyRepository.Instance.RegisterProperty(property); return(property); }
/// <summary> /// 声明一个引用实体属性。 /// </summary> /// <typeparam name="TRefEntity"></typeparam> /// <param name="propertyExp">指向引用实体属性的表达式。</param> /// <param name="refIdProperty">对应的引用 Id 属性,将为其建立关联。</param> /// <returns></returns> public static RefEntityProperty <TRefEntity> RegisterRef <TRefEntity>(Expression <Func <TEntity, TRefEntity> > propertyExp, IRefIdProperty refIdProperty) where TRefEntity : Entity { if (refIdProperty == null) { throw new ArgumentNullException("refIdProperty", "必须指定引用 Id 属性,将为其建立关联。"); } var defaultMeta = new PropertyMetadata <Entity>(); defaultMeta.AffectStatus = false; var property = new RefEntityProperty <TRefEntity>(typeof(TEntity), GetPropertyName(propertyExp), defaultMeta) { RefIdProperty = refIdProperty }; //默认只从服务端序列化到客户端。 defaultMeta.Serializable = RafyEnvironment.IsOnServer(); ManagedPropertyRepository.Instance.RegisterProperty(property); return(property); }
/// <summary> /// 以懒加载的方式获取某个引用实体的值。 /// </summary> /// <typeparam name="TRefEntity"></typeparam> /// <param name="entityProperty"></param> /// <returns></returns> public TRefEntity GetRefEntity <TRefEntity>(RefEntityProperty <TRefEntity> entityProperty) where TRefEntity : Entity { return(this.GetRefEntity(entityProperty as IRefEntityProperty) as TRefEntity); }