Пример #1
0
        public void TestMakeType()
        {
            ClrClassPath p = "UnitTest.Sample, Assembly = UnitTest.dll";
            Type         t = p.MakeType("Person");

            Assert.NotNull(t);
        }
Пример #2
0
        public CLRLocator(string path)
        {
            ClrClassPath clrPath = path;

            _namespace    = clrPath.ClassPath;
            _assemblyName = clrPath.AssemblyName;
        }
Пример #3
0
        public void TestCreate()
        {
            ClrClassPath p = "UnitTest.Sample, Assembly = UnitTest.dll";

            Assert.AreEqual("UnitTest.dll", p.AssemblyName);
            Assert.AreEqual("UnitTest.Sample", p.ClassPath);
        }
Пример #4
0
        public void TestCombine()
        {
            ClrClassPath p = "UnitTest, Assembly = UnitTest.dll";

            p = p.Navigate("Sample");
            Assert.AreEqual("UnitTest.dll", p.AssemblyName);
            Assert.AreEqual("UnitTest.Sample", p.ClassPath);
        }
Пример #5
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);
            }
        }