Exemplo n.º 1
0
        private Dictionary <MetaDataMember, Func <object, object> > GetGetterTableMap(Type tableType)
        {
            AttributeMappingSource mappingSource = new AttributeMappingSource();
            MetaModel mapping = mappingSource.GetModel(tableType);
            MetaTable table   = mapping.GetTable(tableType);

            Dictionary <MetaDataMember, Func <object, object> > mappedTable = new Dictionary <MetaDataMember, Func <object, object> >();

            foreach (MetaDataMember dataMember in table.RowType.PersistentDataMembers)
            {
                MemberInfo memberInfo = dataMember.Member;
                Expression <Func <object, object> > getter = null;
                if (memberInfo is FieldInfo)
                {
                    getter = (Expression <Func <object, object> >)(o => ((FieldInfo)memberInfo).GetValue(o));
                }
                else if (memberInfo is PropertyInfo)
                {
                    getter = (Expression <Func <object, object> >)(o => ((PropertyInfo)memberInfo).GetGetMethod().Invoke(o, new object[0]));
                }
                else
                {
                    throw new ApplicationException("GetTableMap could not determine lambda expression for " + memberInfo.GetType() + ".");
                }
                mappedTable.Add(dataMember, getter.Compile());
            }

            return(mappedTable);
        }
Exemplo n.º 2
0
    protected override MetaModel CreateModel(Type dataContextType)
    {
        MetaModel       oldmodel = mapping.GetModel(dataContextType);
        CustomMetaModel newmodel = new CustomMetaModel(oldmodel, _customTableNames);

        return(newmodel);
    }
Exemplo n.º 3
0
        private string GetTableName(Type tableType)
        {
            AttributeMappingSource mappingSource = new AttributeMappingSource();
            MetaModel mapping = mappingSource.GetModel(tableType);
            MetaTable table   = mapping.GetTable(tableType);

            return(table.TableName);
        }
Exemplo n.º 4
0
        public void ProviderAndDatabaseNameTest()
        {
            //Test Provider
            var mappingSource = new AttributeMappingSource();
            var model         = mappingSource.GetModel(typeof(Database1));

            Assert.AreSame(typeof(AccessDbProvider), model.ProviderType);
            //Test DatabaseName
            Assert.AreEqual <string>("Northwind", model.DatabaseName);
        }
Exemplo n.º 5
0
        public void TableTest()
        {
            var mappingSource = new AttributeMappingSource();
            var model         = mappingSource.GetModel(typeof(Database2));
            var metaTables    = model.GetTables().ToArray();

            //Test meta tables Count
            Assert.AreEqual(2, metaTables.Count());

            //Test meta table name.
            Assert.AreEqual("Table1", metaTables[0].TableName);
            Assert.AreEqual("Table2", metaTables[1].TableName);
        }
Exemplo n.º 6
0
        private Type GetMemberType(MemberExpression m)
        {
            AttributeMappingSource mappingSource = new AttributeMappingSource();
            MetaModel mapping = mappingSource.GetModel(m.Member.DeclaringType);
            MetaTable table   = mapping.GetTable(m.Member.DeclaringType);

            foreach (MetaDataMember dataMember in table.RowType.PersistentDataMembers)
            {
                if (dataMember.Name == m.Member.Name)
                {
                    return(dataMember.Type);
                }
            }
            return(null);
        }
Exemplo n.º 7
0
 protected override MetaModel CreateModel(Type dataContextType)
 {
     return(new CustomMetaModel(mapping.GetModel(dataContextType), Shema));
 }