Beispiel #1
0
 private static void AssignKey(PropertyAccessor property, PropertyToColumn column, ICollection <PropertyToColumn> ids)
 {
     column.IsKey = true;
     if (property.IsPrimitiveInteger())
     {
         column.IsIdentity = true;
         column.IsComputed = true;
         ids.Add(column);
     }
 }
Beispiel #2
0
        public void Describe()
        {
            All.Clear();
            var ids        = new List <PropertyToColumn>();
            var properties = ProjectFromComponentModel().ToList();

            foreach (var property in properties)
            {
                if (Exists(property) || property.Has <TransientAttribute>())
                {
                    continue;
                }

                var column = new PropertyToColumn(property)
                {
                    IsComputed = property.Has <ComputedAttribute>()
                };

                All.Add(column);

                if (column.Property.Name.EndsWith("id", true, CultureInfo.InvariantCulture))
                {
                    AssignKey(property, column, ids);
                }

                if (column.Property.Name.Equals("createdat", StringComparison.OrdinalIgnoreCase))
                {
                    column.IsComputed = true;
                }
            }

            MakeCompositeKeyIfMultiplePossibleIdentities(ids);

            foreach (var property in properties)
            {
                if (property.Has <IdentityAttribute>())
                {
                    var column = All.SingleOrDefault(a => a.ColumnName.Equals(property.Name));
                    if (column != null)
                    {
                        column.IsIdentity = true;
                        column.IsComputed = true;
                    }
                }
            }
        }