Beispiel #1
0
    /// <summary>
    /// 获取分片实体的属性信息。
    /// </summary>
    /// <param name="entity">给定的 <see cref="ShardingEntity"/>。</param>
    /// <returns>返回 <see cref="PropertyInfo"/>。</returns>
    protected virtual PropertyInfo?GetEntityProperty(ShardingEntity entity)
    {
        PropertyInfo?propertyInfo = null;

        foreach (var property in entity.EntityType.GetProperties())
        {
            foreach (var key in entity.PropertyKeys)
            {
                if (property.PropertyType == key.SourceType &&
                    property.Name == key.SourceAliase)
                {
                    propertyInfo = property;
                    break;
                }
            }

            if (propertyInfo is not null)
            {
                break;
            }
        }

        return(propertyInfo);
    }
 /// <summary>
 /// 增加或设置分片实体。
 /// </summary>
 /// <param name="entity">给定的 <see cref="ShardingEntity"/>。</param>
 /// <returns>返回 <see cref="IShardingManager"/>。</returns>
 public virtual IShardingManager AddOrSetEntity(ShardingEntity entity)
 {
     _entities.AddOrUpdate(entity.EntityType, entity,
                           (key, value) => value.AddOrSetProperties(entity.Properties));
     return(this);
 }