Exemplo n.º 1
0
        public IObjectMapInfo GetMapInfo(Type entityType, bool throwOnNotFound)
        {
            if (_cache.ContainsKey(entityType))
            {
                return(_cache[entityType]);
            }
            else
            {
                if (throwOnNotFound)
                {
                    MappingInfoExceptionHelper.ThrowMappingInformationNotFound(entityType);
                }

                return(null);
            }
        }
Exemplo n.º 2
0
        private void Load(XDoc doc)
        {
            Assertion.AreEqual("ormap", doc.Node.Name, "Root element should be [ormap].");
            foreach (XAccessor x in doc.Attributes)
            {
                Assertion.AreEqual("xmlns", x.Prefix, "Only xmlns attributes allowed in root element.");
                string tag    = x.LocalName;
                string target = x.GetStringValue();

                if (target.StartsWith(DbPath.DB_SCHEMA))
                {
                    DbPath dbPath = target.RemoveBegin(DbPath.DB_SCHEMA);
                    Assertion.IsTrue(ORMConfig.ORMConfiguration.ExistDatabase(dbPath.DatabaseId), "Database [{0}] is not defined.", dbPath.DatabaseId);

                    _dbDict.Add(tag, dbPath);
                }
                else if (target.StartsWith(ClrClassPath.CLR_SCHEME))
                {
                    ClrClassPath path = target.RemoveBegin(ClrClassPath.CLR_SCHEME);
                    _clrDict.Add(tag, path);
                }
                else
                {
                    Assertion.Fail("Unknown schema of uri [{0}].", target);
                }
            }

            var mapList = doc.NavigateToList("object-table-map");

            foreach (var xMap in mapList)
            {
                PrefixedName c          = new PrefixedName(xMap.GetStringValue("@class"));
                PrefixedName t          = new PrefixedName(xMap.GetStringValue("@table"));
                string       primaryKey = xMap.GetStringValue("@primaryKey");
                string       pkGenerate = xMap.GetStringValue("@primaryKeyGenerate");

                Assertion.IsTrue(_clrDict.ContainsKey(c.Prefix), "Prefix [{0}] is not defined.", c.Prefix);
                Type entityType = _clrDict[c.Prefix].MakeType(c.LocalName);

                if (entityType == null)
                {
                    MappingInfoExceptionHelper.ThrowLoadEntityTypeFail(c.Prefix, c.LocalName);
                }

                var fields = xMap.NavigateToList("field");
                List <IPropertyMapInfo> list = new List <IPropertyMapInfo>();
                foreach (var xField in fields)
                {
                    string property = xField.GetStringValue("@property");
                    string column   = xField.GetStringValue("@column");

                    int  length   = xField.GetValue <int>("@length") ?? 0;
                    bool nullable = xField.GetValue <bool>("@nullable") ?? true;

                    IPropertyMapInfo pInfo = new PropertyMapInfo(property, column, length, nullable);
                    list.Add(pInfo);
                }

                IObjectMapInfo info = new ObjectMapInfo(t, entityType, primaryKey, pkGenerate, list);
                _cache.SetMapInfo(entityType, info);
            }
        }