Example #1
0
            private static ICollection <AttrMetaData> Identity(TableProperty prop, ICollection <TableProperty> properties)
            {
                if (!prop.IsIdentity || prop.IsKey)
                {
                    return(null);
                }

                var attr = new AttrMetaData {
                    Name = "DatabaseGenerated"
                };

                attr.Params.Add(new KeyValuePair <string, string>("", "DatabaseGeneratedOption.Identity"));

                return(new[] { attr });;
            }
Example #2
0
            private static ICollection <AttrMetaData> Rename(TableProperty prop, ICollection <TableProperty> properties)
            {
                var sanitizedName = Shared.NameSanitize(prop.ColumnName);

                if (prop.ColumnName.Length == sanitizedName.Length)
                {
                    return(null);
                }

                var attr = new AttrMetaData {
                    Name = "Column"
                };

                attr.Params.Add(new KeyValuePair <string, string>("", $"\"{prop.ColumnName}\""));

                return(new[] { attr });
            }
Example #3
0
            private static ICollection <AttrMetaData> StringLength(TableProperty prop, ICollection <TableProperty> properties)
            {
                if (prop.Size == null || prop.Size == -1)
                {
                    return(null);
                }

                var attr = new AttrMetaData {
                    Name = "StringLength"
                };

                attr.Params.Add(new KeyValuePair <string, string>("", prop.Size.ToString()));

                if (MinLengthTypes.Contains(prop.DataType))
                {
                    attr.Params.Add(new KeyValuePair <string, string>("MinimumLength", prop.Size.ToString()));
                }

                return(new[] { attr });;
            }
Example #4
0
            private static ICollection <AttrMetaData> DbNone(TableProperty prop, ICollection <TableProperty> properties)
            {
                if (!prop.IsKey || prop.IsIdentity)
                {
                    return(null);
                }

                // composite PK not db generated is implied
                if (properties.Count(x => x.IsKey) > 1)
                {
                    return(null);
                }

                var attr = new AttrMetaData {
                    Name = "DatabaseGenerated"
                };

                attr.Params.Add(new KeyValuePair <string, string>("", "DatabaseGeneratedOption.None"));

                return(new[] { attr });;
            }
Example #5
0
            private static ICollection <AttrMetaData> DataType(TableProperty prop, ICollection <TableProperty> properties)
            {
                if (StringTypes.Contains(prop.DataType))
                {
                    var attr = new AttrMetaData {
                        Name = "Column"
                    };
                    attr.Params.Add(new KeyValuePair <string, string>("TypeName", $"\"{prop.DataType}({(prop.Size > -1 ? prop.Size.ToString() : "MAX")})\""));
                    return(new[] { attr });
                }


                if (NumericTypes.Contains(prop.DataType))
                {
                    var attr = new AttrMetaData {
                        Name = "Column"
                    };
                    attr.Params.Add(new KeyValuePair <string, string>("TypeName", $"\"{prop.DataType}({prop.Precision}, {prop.Scale})\""));
                    return(new[] { attr });
                }

                return(null);
            }
Example #6
0
            private static ICollection <AttrMetaData> Key(TableProperty prop, ICollection <TableProperty> properties)
            {
                if (!prop.IsKey)
                {
                    return(null);
                }

                var attrs = new List <AttrMetaData> {
                    new AttrMetaData {
                        Name = "Key"
                    }
                };

                if (properties.Count(x => x.IsKey) > 1)
                {
                    var order = -1;
                    for (int i = 0; i < properties.Count; i++)
                    {
                        var tableProperty = properties.ElementAt(i);
                        if (tableProperty.IsKey)
                        {
                            order++;

                            if (tableProperty.ColumnName == prop.ColumnName)
                            {
                                var columnAttr = new AttrMetaData {
                                    Name = "Column"
                                };
                                columnAttr.Params.Add(new KeyValuePair <string, string>("Order", order.ToString()));
                                attrs.Add(columnAttr);
                            }
                        }
                    }
                }

                return(attrs);
            }