当前位置: 首页>>代码示例>>C#>>正文


C# Class.MakeUniqueName方法代码示例

本文整理汇总了C#中Class.MakeUniqueName方法的典型用法代码示例。如果您正苦于以下问题:C# Class.MakeUniqueName方法的具体用法?C# Class.MakeUniqueName怎么用?C# Class.MakeUniqueName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Class的用法示例。


在下文中一共展示了Class.MakeUniqueName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddEntitySet

        /// <summary>
        /// add children tables
        /// </summary>
        /// <param name="clss"></param>
        /// <param name="constructor"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        private Property AddEntitySet(Class clss, Constructor constructor, IForeignKey key)
        {
            TableName fk_tname = new TableName(tname.DatabaseName, key.FK_Schema, key.FK_Table);
            string fk_cname = fk_tname.ToClassName(null);
            string pname;

            Property prop;
            TypeInfo ty;
            Field field;

            var fk_schema = GetSchema(fk_tname);
            var _keys = fk_schema.PrimaryKeys.Keys;

            if (_keys.Length == 1 && _keys.Contains(key.FK_Column))
            {
                // 1:1 mapping
                pname = clss.MakeUniqueName(Pluralization.Singularize(fk_cname));
                ty = new TypeInfo { userType = $"EntityRef<{fk_cname}>" };
                field = new Field(ty, $"_{pname}") { modifier = Modifier.Private };

                prop = new Property(new TypeInfo { userType = fk_cname }, pname) { modifier = Modifier.Public };
                prop.gets.Append($"return this._{pname}.Entity;");
                prop.sets.Append($"this._{pname}.Entity = value;");

                prop.AddAttribute(new AttributeInfo("Association",
                 new
                 {
                     Name = $"{this.cname}_{fk_cname}",
                     Storage = $"_{pname}",
                     ThisKey = key.PK_Column,
                     OtherKey = key.FK_Column,
                     IsUnique = true,
                     IsForeignKey = false
                 }));
            }
            else
            {
                //1:n mapping
                pname = clss.MakeUniqueName(Pluralization.Pluralize(fk_cname));
                constructor.statements.AppendLine($"this._{pname} = new EntitySet<{fk_cname}>();");

                ty = new TypeInfo { userType = $"EntitySet<{fk_cname}>" };
                field = new Field(ty, $"_{pname}") { modifier = Modifier.Private };

                prop = new Property(ty, pname) { modifier = Modifier.Public };
                prop.gets.Append($"return this._{pname};");
                prop.sets.Append($"this._{pname}.Assign(value);");

                prop.AddAttribute(new AttributeInfo("Association",
                 new
                 {
                     Name = $"{this.cname}_{fk_cname}",
                     Storage = $"_{pname}",
                     ThisKey = key.PK_Column,
                     OtherKey = key.FK_Column,
                     IsForeignKey = false
                 }));
            }

            clss.Add(field);

            return prop;
        }
开发者ID:fjiang2,项目名称:sqlcon,代码行数:70,代码来源:Linq2SQLClassBuilder.cs

示例2: AddEntityRef

        /// <summary>
        /// add foreighn keys
        /// </summary>
        /// <param name="clss"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        private Property AddEntityRef(Class clss, IForeignKey key)
        {
            string pk_cname = new TableName(tname.DatabaseName, key.PK_Schema, key.PK_Table).ToClassName(null);
            string pname = clss.MakeUniqueName(pk_cname);

            var field = new Field(new TypeInfo { userType = $"EntityRef<{pk_cname}>" }, $"_{pname}") { modifier = Modifier.Private };
            clss.Add(field);

            var prop = new Property(new TypeInfo { userType = pk_cname }, pname) { modifier = Modifier.Public };
            prop.gets.Append($"return this._{pname}.Entity;");
            prop.sets.Append($"this._{pname}.Entity = value;");
            prop.AddAttribute(new AttributeInfo("Association",
                new
                {
                    Name = $"{pk_cname}_{this.cname}",
                    Storage = $"_{pname}",
                    ThisKey = key.FK_Column,
                    OtherKey = key.PK_Column,
                    IsForeignKey = true
                }));
            return prop;
        }
开发者ID:fjiang2,项目名称:sqlcon,代码行数:28,代码来源:Linq2SQLClassBuilder.cs


注:本文中的Class.MakeUniqueName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。