public void Setup()
            {
                Given(ObjectBuilder_is_created);

                And("parts for lists of customers are specified", () =>
                {
                    part             = new Part(typeof(List <Customer>));
                    var customerPart = new ValuePart(typeof(Customer));
                    customerPart.Describe(m => m.Count = 10);
                    customerPart.AddPart(new PropertyPart("Name", typeof(string))).
                    Describe(m =>
                    {
                        m.Data.Add("HumanName", HumanNameOptions.Name);
                    });

                    var ceoPart = new PropertyPart("CEO", typeof(Employee));
                    ceoPart.AddPart(new PropertyPart("Name", typeof(string))).
                    Describe(metadata =>
                             metadata.Data.Add("HumanName", HumanNameOptions.Name | HumanNameOptions.Surname));
                    customerPart.AddPart(ceoPart);
                    part.AddPart(customerPart);
                });

                When(build_object_graph);
            }
Beispiel #2
0
            public void Setup()
            {
                Given(Part_is_created);

                When("created new Property part", () =>
                     newPart = new PropertyPart("child", typeof(string)));
            }
Beispiel #3
0
        private static PropertyPart TimePartWithDatabaseDefault <TEntity>(PropertyPart datePart, Dialect dialect)
        {
            if (dialect is MsSql2005Dialect)
            {
                datePart.Default("GETUTCDATE()");
            }

            if (dialect is MsSql2008Dialect)
            {
                datePart.Default("GETUTCDATE()");
            }

            if (dialect is Oracle10gDialect)
            {
                datePart.Default("SYSTIMESTAMP AT TIME ZONE 'UTC'");
            }

            if (dialect is SQLiteDialect)
            {
                datePart.Default("(datetime('now'))");
            }

            if (dialect is FirebirdDialect)
            {
                datePart.Default("current_date");
            }

            if (dialect is PostgreSQLDialect)
            {
                datePart.Default("current_timestamp");
            }

            return(datePart);
        }
Beispiel #4
0
 /// <summary>
 /// Uses the correct nhibernate custom mapping type for a Property that is based on a Concept
 /// </summary>
 /// <typeparam name="T">Concrete type of the concept, that inherits from <see cref="ConceptAs{U}"/></typeparam>
 /// <typeparam name="U">The primitive that is the concept is based on</typeparam>
 /// <param name="propertyPart">Fluent NHibernate PropertyPart</param>
 /// <returns>Fluent NHibernate PropertyPart<</returns>
 public static PropertyPart ConceptOf <T, U>(this PropertyPart propertyPart)
     where U : IEquatable <U>
     where T : ConceptAs <U>
 {
     propertyPart.CustomType <ConceptValueType <T, U> >();
     return(propertyPart);
 }
Beispiel #5
0
        public static PropertyPart JsonSerialized(this PropertyPart propertyPart)
        {
            var jsonType     = typeof(JsonSerializedObjectType <>);
            var propertyType = ((IPropertyMappingProvider)propertyPart).GetPropertyMapping().Member.PropertyType;

            var customType = jsonType.MakeGenericType(propertyType);

            return(propertyPart.CustomType(customType));
        }
 public static PropertyPart MapNVarchar(this PropertyPart source, int length)
 {
     return(source
            .CustomType("StringClob")
            .CustomSqlType(
                "nvarchar({0})".FillWith(length.ToSQL())
                )
            .Length(length));
 }
 public static PropertyPart MapVarbinary(this PropertyPart source, int length)
 {
     return(source
            .CustomType("BinaryBlob")
            .CustomSqlType(
                "varbinary({0})".FillWith(length.ToSQL())
                )
            .Length(length));
 }
            public void Setup()
            {
                Given(ObjectBuilder_is_created);

                And("part for a complex object is specified", () =>
                {
                    part = new Part(typeof(Customer));
                    part.AddPart(new PropertyPart("CEO", typeof(Employee)));
                    var employeesProperty = new PropertyPart("Employees", typeof(ObservableCollection <Employee>));
                    part.AddPart(employeesProperty);

                    employeesProperty.AddPart(new ValuePart(typeof(Employee)));
                });

                When(build_object_graph);
            }
        public static PropertyPart Index(this PropertyPart propertyPart)
        {
            FieldInfo parentField = typeof(PropertyPart).GetRuntimeFields().FirstOrDefault(item => item.Name == "parentType");
            FieldInfo memberField = typeof(PropertyPart).GetRuntimeFields().FirstOrDefault(item => item.Name == "member");

            System.Type entityType = parentField.GetValue(propertyPart) as System.Type;
            Member      memberType = memberField.GetValue(propertyPart) as Member;

            string idx_name = string.Format("idx_{0}_{1}",
                                            LowerImprovedNamingStrategy.Instance.ClassToTableName(entityType.Name),
                                            LowerImprovedNamingStrategy.Instance.PropertyToColumnName(memberType.Name)
                                            );

            propertyPart.Index(idx_name);
            return(propertyPart);
        }
        public static NaturalIdPart <T> Property <T>(
            this NaturalIdPart <T> naturalIdPart,
            Expression <Func <T, object> > expression,
            Action <PropertyPart> propertyAction)
        {
            naturalIdPart.ThrowIfNull("this");
            expression.ThrowIfNull("expression");
            propertyAction.ThrowIfNull("propertyAction");

            var propertyPart = new PropertyPart(expression.ToMember(), typeof(T));

            propertyAction(propertyPart);
            naturalIdPart.GetProperties().Add((propertyPart as IPropertyMappingProvider).GetPropertyMapping());

            return(naturalIdPart);
        }
        /// <summary>
        /// Splits a property name into its component parts.
        /// </summary>
        /// <param name="propertyName">The property to split.</param>
        /// <returns>An array of component parts.</returns>
        public static PropertyPart[] SplitPropertyName(string propertyName)
        {
            // Split into the dot separated parts
            string[]            parts   = propertyName.Split('.');
            List <PropertyPart> results = new List <PropertyPart>();

            foreach (string part in parts)
            {
                PropertyPart newPart = new PropertyPart();

                // Check if each part has a key
                int keyIndex = part.IndexOf('[');
                if (keyIndex >= 0)
                {
                    // If so, find the different parts
                    newPart.Name = part.Substring(0, keyIndex);
                    string key         = part.Substring(keyIndex + 1);
                    int    equalsIndex = key.IndexOf('=');
                    if (equalsIndex >= 0)
                    {
                        newPart.KeyName  = key.Substring(0, equalsIndex);
                        newPart.KeyValue = key.Substring(equalsIndex + 1);
                        newPart.KeyValue = newPart.KeyValue.Remove(newPart.KeyValue.Length - 1);
                    }
                    else
                    {
                        int index;
                        if (int.TryParse(key.Substring(0, key.Length - 1), out index))
                        {
                            newPart.Index = index;
                        }
                    }
                }
                else
                {
                    // Otherwise the whole is the name
                    newPart.Name = part;
                }
                results.Add(newPart);
            }

            return(results.ToArray());
        }
Beispiel #12
0
            public void Setup()
            {
                Given(ObjectBuilder_is_created);

                And("part for list of objects is specified", () =>
                {
                    part = new Part(typeof(List <Customer>));
                    var customer1Part = new ValuePart(typeof(Customer));
                    customer1Part.AddPart(new PropertyPart("CEO", typeof(Employee)));
                    var employeesPart = new PropertyPart("Employees", typeof(ObservableCollection <Employee>));
                    var employeePart  = new ValuePart(typeof(Employee));
                    employeePart.AddPart(new PropertyPart("Boss", typeof(Employee)));

                    employeesPart.AddPart(employeePart);
                    customer1Part.AddPart(employeesPart);

                    part.AddPart(customer1Part);
                    part.AddPart(new ValuePart(typeof(Customer)));
                });

                When(build_object_graph);
            }
Beispiel #13
0
 public static PropertyPart AsDate(this PropertyPart map)
 {
     return(map.CustomType("date"));
 }
 public static PropertyPart MapDateTime(this PropertyPart source)
 {
     return(source
            .CustomType("datetime2"));
 }
 public static PropertyPart MapVarbinaryMax(this PropertyPart source)
 {
     return(source.MapVarbinary(int.MaxValue));
 }
Beispiel #16
0
 public static PropertyPart BooleanoSimNao(this PropertyPart propertyPart)
 {
     return(propertyPart.CustomType <SimNaoType>());
 }
 public static PropertyPart MapNVarcharMax(this PropertyPart source)
 {
     return(source.MapNVarchar(int.MaxValue));
 }
 public static PropertyPart Indexable(this PropertyPart propertyPart)
 {
     return(propertyPart.Index("___Indexable"));
 }
Beispiel #19
0
 public static PropertyPart StringMaxLength(this PropertyPart propertyPart)
 {
     return(propertyPart.CustomType("StringClob"));
 }
 public static PropertyPart LargeTextColumn(this PropertyPart pp)
 {
     return(pp.CustomSqlType(_ClobSqlType));
 }
Beispiel #21
0
 public static PropertyPart VarCharMax(this PropertyPart part)
 {
     //Any length more than 4001 sets the string column to varchar(MAX) or Text.
     return(part.Length(4444));
 }
Beispiel #22
0
 /// <summary>
 ///     Shortcut to make a property varchar(max) as you have to explicitly set the length otherwise
 /// </summary>
 /// <param name="propertyPart"></param>
 /// <returns></returns>
 public static PropertyPart MakeVarCharMax(this PropertyPart propertyPart)
 {
     return(propertyPart.CustomType <VarcharMax>().Length(4001));
 }
Beispiel #23
0
 public static PropertyPart Money(this PropertyPart propertyPart)
 {
     propertyPart.CustomType <MoneyUserType>();
     return(propertyPart);
 }
 public static PropertyPart AsEnumString <T>(this PropertyPart propertyPart)
 {
     return(propertyPart.CustomType <EnumStringType <T> >());
 }
Beispiel #25
0
 public static PropertyPart AsYesNoBoolean(this PropertyPart map)
 {
     return(map.CustomType("YesNo"));
 }
Beispiel #26
0
 public static PropertyPart WithMaxLength(this PropertyPart propertyPart)
 {
     return(propertyPart.Length(10000));
 }
 public static PropertyPart AsClob(this PropertyPart propertyPart)
 {
     return(propertyPart.CustomType("StringClob").CustomSqlType("nvarchar(max)"));
 }
Beispiel #28
0
 public static PropertyPart Text(this PropertyPart propertyPart)
 {
     propertyPart.Length(10000);
     return(propertyPart);
 }
        /// <summary>
        /// Splits a property name into its component parts.
        /// </summary>
        /// <param name="propertyName">The property to split.</param>
        /// <returns>An array of component parts.</returns>
        public static PropertyPart[] SplitPropertyName(string propertyName)
        {
            // Split into the dot separated parts
            string[] parts = propertyName.Split('.');
            List<PropertyPart> results = new List<PropertyPart>();

            foreach (string part in parts)
            {
                PropertyPart newPart = new PropertyPart();

                // Check if each part has a key
                int keyIndex = part.IndexOf('[');
                if (keyIndex >= 0)
                {
                    // If so, find the different parts
                    newPart.Name = part.Substring(0, keyIndex);
                    string key = part.Substring(keyIndex + 1);
                    int equalsIndex = key.IndexOf('=');
                    if (equalsIndex >= 0)
                    {
                        newPart.KeyName = key.Substring(0, equalsIndex);
                        newPart.KeyValue = key.Substring(equalsIndex + 1);
                        newPart.KeyValue = newPart.KeyValue.Remove(newPart.KeyValue.Length - 1);
                    }
                    else
                    {
                        int index;
                        if (int.TryParse(key.Substring(0, key.Length - 1), out index))
                        {
                            newPart.Index = index;
                        }
                    }
                }
                else
                {
                    // Otherwise the whole is the name
                    newPart.Name = part;
                }
                results.Add(newPart);
            }

            return results.ToArray();
        }
        public Result.IfSuccess <BindingSource> VisitPropertyPart(PropertyPart propertyPart, Parameters parameters, Context context)
        {
            var codeGenerator = new PropertyAccessorCodeGenerator(context, this.typeResolver, propertyPart.Name, false);

            return(this.targetBindingPartCodeGenerator.GeneratePartBinding(parameters.Binding.BindingAssignment.Mode, this.targetValue, context, codeGenerator));
        }
 public PropertyGeneratedBuilder(PropertyPart parent, Action<string> setter)
 {
     this.parent = parent;
     this.setter = setter;
 }
Beispiel #32
0
 /// <summary>
 /// The default.
 /// </summary>
 /// <param name="propertyPart">
 /// The property part.
 /// </param>
 /// <typeparam name="T">
 /// </typeparam>
 /// <returns>
 /// The <see cref="PropertyPart"/>.
 /// </returns>
 public static PropertyPart Default <T>(this PropertyPart propertyPart)
 {
     return(propertyPart.Default(default(T).ToString()));
 }