public void GetPropertyName()
        {
            #region GetPropertyName
            var propName = PropertyName <Person> .GetPropertyName((p) => p.FirstName);

            #endregion
        }
Ejemplo n.º 2
0
        private void MapExternalClass()
        {
            #region MapExternalClass
            var externalPersonMap = new Dictionary <string, string>()
            {
                { PropertyName <ExternalPerson> .GetPropertyName(p => p.oId), "Id" },
                { PropertyName <ExternalPerson> .GetPropertyName(p => p.Name), "FirstName" },
                { PropertyName <ExternalPerson> .GetPropertyName(p => p.SecondName), "LastName" }
            };

            Database.DefaultModelMapper.MapColumnName = (colInfo, modelType) =>
            {
                if (modelType == typeof(ExternalPerson))
                {
                    return(externalPersonMap[colInfo.PropertyInfo.Name]);
                }
                else
                {
                    return(colInfo.PropertyInfo.Name);
                }
            };

            using (var database = new Database(_connection))
            {
                var people = database.Query <ExternalPerson>();

                foreach (var person in people)
                {
                    Console.WriteLine($"{person.oId} : {person.Name}-{person.SecondName}");
                }
            }
            #endregion
        }
Ejemplo n.º 3
0
        IPrimaryKeyBuilder <TEntity> INamedEntityTypeBuilder <TEntity> .HasPrimaryKey <TProperty>(
            Expression <Func <TEntity, TProperty> > propertyExpression)
        {
            Check.NotNull(propertyExpression, nameof(propertyExpression));
            _primaryKeyPropertyName = PropertyName <TEntity> .GetPropertyName(propertyExpression);

            return(this);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Set column name for specific property.
        /// </summary>
        /// <param name="modelProperty">Expression for defined property to.</param>
        /// <param name="columnName">Database column name.</param>
        /// <example>
        /// <code source="..\..\Documentation\Examples\Kros.KORM.Examples\ModelMapperExample.cs" title="SetColumnName" region="SetColumnName" language="cs" />
        /// </example>
        public void SetColumnName <TModel, TValue>(Expression <Func <TModel, TValue> > modelProperty, string columnName)
            where TModel : class
        {
            Check.NotNull(modelProperty, nameof(modelProperty));
            Check.NotNullOrEmpty(columnName, nameof(columnName));

            ((IModelMapperInternal)this).SetColumnName <TModel>(PropertyName <TModel> .GetPropertyName(modelProperty), columnName);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Set column name for specific property.
        /// </summary>
        /// <param name="modelProperty">Expression for defined property to.</param>
        /// <param name="columnName">Database column name.</param>
        /// <example>
        /// <code source="..\Examples\Kros.KORM.Examples\ModelMapperExample.cs" title="SetColumnName" region="SetColumnName" lang="C#"  />
        /// </example>
        public void SetColumnName <TModel, TValue>(Expression <Func <TModel, TValue> > modelProperty, string columnName) where TModel : class
        {
            Check.NotNull(modelProperty, nameof(modelProperty));
            Check.NotNullOrEmpty(columnName, nameof(columnName));

            if (!_columnMap.ContainsKey(typeof(TModel)))
            {
                _columnMap[typeof(TModel)] = new Dictionary <string, string>(StringComparer.CurrentCultureIgnoreCase);
            }

            _columnMap[typeof(TModel)][PropertyName <TModel> .GetPropertyName(modelProperty)] = columnName;
        }
Ejemplo n.º 6
0
        IPropertyBuilder <TEntity> IEntityTypePropertyBuilder <TEntity> .Property <TProperty>(
            Expression <Func <TEntity, TProperty> > propertyExpression)
        {
            Check.NotNull(propertyExpression, nameof(propertyExpression));
            string propertyName = PropertyName <TEntity> .GetPropertyName(propertyExpression);

            if (_propertyBuilders.ContainsKey(propertyName))
            {
                ThrowHelper.PropertyAlreadyConfigured <TEntity>(propertyName);
            }

            var propertyBuilder = new PropertyBuilder <TEntity>(this, propertyName);

            _propertyBuilders.Add(propertyName, propertyBuilder);
            return(propertyBuilder);
        }
Ejemplo n.º 7
0
 public void ReturnPropertyName()
 {
     PropertyName <Foo> .GetPropertyName(p => p.Prop1).Should().Be("Prop1");
 }