Ejemplo n.º 1
0
        protected ClassInfo(string @as, ClassNode classNode)
        {
            _as        = @as;
            _classNode = classNode;
            _joins     = new List <Join>();

            _asName = @as;
        }
Ejemplo n.º 2
0
        public static ClassNode Create(XElement element)
        {
            string attribuleValue;

            var info = new ClassNode();

            if (MappingInfo.GetAttribuleValue(element, "type", out attribuleValue))
            {
                info._typeStr = attribuleValue;
            }

            if (MappingInfo.GetAttribuleValue(element, "name", out attribuleValue) || !(attribuleValue = element.Name.LocalName).Equals("object", StringComparison.OrdinalIgnoreCase))
            {
                info._name = attribuleValue;
            }
            else
            {
                info._name = info.EntityType.Name;
            }

            if (MappingInfo.GetAttribuleValue(element, "table", out attribuleValue))
            {
                info._table = attribuleValue;
            }

            if (MappingInfo.GetAttribuleValue(element, "schema", out attribuleValue))
            {
                info._schema = attribuleValue;
            }

            if (MappingInfo.GetAttribuleValue(element, "inherits", out attribuleValue))
            {
                info._inherit = attribuleValue;
            }

            info._propertyNodeList = new List <PropertyNode>();
            info._joinList         = new List <JoinPropertyNode>();

            foreach (var property in element.Elements())
            {
                if (property.Name.LocalName.Equals("key", StringComparison.OrdinalIgnoreCase))
                {
                    foreach (var key in property.Elements())
                    {
                        var keyPropertyInfo = PropertyNode.Create(key);
                        if (string.IsNullOrWhiteSpace(keyPropertyInfo.Name))
                        {
                            throw new FormatException(string.Format("{0}节点下面有一个主键没有name属性", info.Name));
                        }
                        keyPropertyInfo.IsKey = true;
                        info.AddPropertyNodel(keyPropertyInfo);
                    }
                    continue;
                }
                else if (property.HasElements)
                {
                    var joinPropertyInfo = JoinPropertyNode.Create(info, property);
                    info.JoinList.Add(joinPropertyInfo);
                    continue;
                }

                var propertyInfo = PropertyNode.Create(property);
                if (string.IsNullOrWhiteSpace(propertyInfo.Name))
                {
                    throw new FormatException(string.Format("{0}节点下面有一个property节点没有name属性", info.Name));
                }

                info.AddPropertyNodel(propertyInfo);
            }

            return(info);
        }