Inheritance: IEntityModel
Ejemplo n.º 1
0
        private string PopulateMemberName(EntityModel entity, string sourceMemberName)
        {
            var source = sourceMemberName;
            var memberName = source;

            var i = 1;
            if (string.Equals(entity.ClassName, memberName))
            {
                memberName = source + i;
                i++;
            }

            var memberNames = entity.members.Select(p => p.MemberName)
                .Union(entity.manyToOnes.Select(p => p.MemberName))
                .Union(entity.oneToMany.Select(p => p.MemberName))
                .ToArray();

            while (memberNames.Contains(memberName))
            {
                memberName = source + i;
                i++;
            }

            return memberName;
        }
Ejemplo n.º 2
0
        public IEntityModel Convert(ITableSchema table)
        {
            var entity = new EntityModel { Table = table };
            entity.ClassName = NamingConversion.ClassName(table.TableName);
            foreach (var col in table.AllColumns)
            {
                var member = new MemberModel { Column = col, MemberName = PopulateMemberName(entity, NamingConversion.PropertyName(col.ColumnName)) };
                entity.members.Add(member);
            }

            foreach (var col in table.ForeignKeys)
            {
                var member = new NavigationMemberModel { IsManyToOne = true, Relation = col, MemberName = PopulateMemberName(entity, NamingConversion.ManyToOneName(col)) };
                member.DeclareTypeName = NamingConversion.ClassName(col.OtherTable.TableName);
                entity.manyToOnes.Add(member);
            }

            foreach (var col in table.Children)
            {
                var member = new NavigationMemberModel { Relation = col, MemberName = PopulateMemberName(entity, NamingConversion.QueryableName(col.OtherTable.TableName)) };
                member.DeclareTypeName = NamingConversion.ClassName(col.OtherTable.TableName);
                entity.manyToOnes.Add(member);
            }
            return entity;
        }