Esempio n. 1
0
        private void Load(Assembly assembly)
        {
            foreach (Type type in assembly.GetTypes())
            {
                var table = type.GetSingleAttribute <TableAttribute>();
                if (table != null)
                {
                    List <string>           pkList = new List <string>();
                    List <IPropertyMapInfo> fields = new List <IPropertyMapInfo>();

                    foreach (PropertyInfo property in type.GetProperties())
                    {
                        ColumnAttribute col = property.GetSingleAttribute <ColumnAttribute>(true);
                        if (col != null)
                        {
                            IPropertyMapInfo pInfo = new PropertyMapInfo(property.Name, col.Name, col.Length, col.Nullable);
                            fields.Add(pInfo);
                            if (col.PrimaryKey)
                            {
                                pkList.Add(property.Name);
                            }
                        }
                    }

                    IObjectMapInfo info = new ObjectMapInfo(table.TableName, type, pkList.ToArray().Join(ObjectMapInfo.Composite_PK_Delimiter), table.PrimaryKeyGenerate, fields);
                    _cache.SetMapInfo(type, info);
                }
            }
        }
Esempio n. 2
0
        private void Load(Assembly assembly)
        {
            foreach (Type type in assembly.GetTypes())
            {
                var table = type.GetSingleAttribute<TableAttribute>();
                if (table != null)
                {
                    List<string> pkList = new List<string>();
                    List<IPropertyMapInfo> fields = new List<IPropertyMapInfo>();

                    foreach (PropertyInfo property in type.GetProperties())
                    {
                        ColumnAttribute col = property.GetSingleAttribute<ColumnAttribute>(true);
                        if (col != null)
                        {
                            IPropertyMapInfo pInfo = new PropertyMapInfo(property.Name, col.Name, col.Length, col.Nullable);
                            fields.Add(pInfo);
                            if (col.PrimaryKey)
                                pkList.Add(property.Name);
                        }
                    }

                    IObjectMapInfo info = new ObjectMapInfo(table.TableName, type, pkList.ToArray().Join(ObjectMapInfo.Composite_PK_Delimiter), table.PrimaryKeyGenerate, fields);
                    _cache.SetMapInfo(type, info);
                }
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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);
            }
        }