示例#1
0
 private Property CreateProperty(Entity newEntity, Mapping mapping, id hId)
 {
     if (hId.column1 != null)
         return CreateProperty(newEntity, mapping, hId.type1, hId.name, hId.column1, hId.length);
     else
         return CreateProperty(newEntity, mapping, hId.type1, hId.name, hId.column[0].name, hId.length);
 }
示例#2
0
        private static id SetupSingleColumnPrimaryKey(Entity entity)
        {
            IEnumerable<Property> primaryKeyProperties = entity.Key.Properties;
            Property primaryKeyProperty = primaryKeyProperties.FirstOrDefault(p => p.MappedColumn() != null);
            IColumn column = null;

            if (primaryKeyProperty == null)
            {
                if (entity.IsAbstract)
                {
                    // Search the children and grandchildren for the actual mapped column
                    primaryKeyProperty = primaryKeyProperties.FirstOrDefault();
                    column = GetSingleColumnPrimaryKeyFromChildren(entity, primaryKeyProperty.Name);
                }
                if (column == null)
                {
                    var msg = "Could not find mapped property for primary key in entity " + entity.Name;
                    Log.Error(msg);
                    throw new Exception(msg);
                }
            }
            if (column == null)
                column = primaryKeyProperty.MappedColumn();

            id newClassId = new id
            {
                access = AccessTypes.property.ToString(),
                column1 = column.Name.BackTick(),
                name = primaryKeyProperty.Name,
            };

            //if (column.IsIdentity)
            //{
            if (!string.IsNullOrEmpty(entity.Generator.ClassName) &&
                entity.Generator.ClassName != "unknown")
            {
                newClassId.generator = new generator
                {
                    // TODO: handle other generator types that require params
                    //@class = GeneratorTypes.native.ToString()
                    @class = entity.Generator.ClassName
                };
                bool isCustomGenerator = Enum.GetNames(typeof(GeneratorTypes)).Contains(entity.Generator.ClassName);
                int countOfParams;

                if (isCustomGenerator)
                    countOfParams = entity.Generator.Parameters.Where(p => !string.IsNullOrEmpty(p.Value.Trim())).Count();
                else
                    countOfParams = entity.Generator.Parameters.Count;

                newClassId.generator.param = new param[countOfParams];

                for (int paramIndex = 0; paramIndex < entity.Generator.Parameters.Count; paramIndex++)
                {
                    if (!isCustomGenerator ||
                        !string.IsNullOrEmpty(entity.Generator.Parameters[paramIndex].Value.Trim()))
                    {
                        newClassId.generator.param[paramIndex] = new param();
                        newClassId.generator.param[paramIndex].name = entity.Generator.Parameters[paramIndex].Name;
                        newClassId.generator.param[paramIndex].Text = new string[] { entity.Generator.Parameters[paramIndex].Value };
                    }
                }
            }
            //}
            if (column.Size > 0)
            {
                newClassId.length = column.Size.ToString();
            }
            return newClassId;
        }
 public static void SetId(this @class theClass, id Id)
 {
     theClass.Item = Id;
 }