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); }
protected override MetaModel CreateModel(Type dataContextType) { MetaModel oldmodel = mapping.GetModel(dataContextType); CustomMetaModel newmodel = new CustomMetaModel(oldmodel, _customTableNames); return(newmodel); }
private string GetTableName(Type tableType) { AttributeMappingSource mappingSource = new AttributeMappingSource(); MetaModel mapping = mappingSource.GetModel(tableType); MetaTable table = mapping.GetTable(tableType); return(table.TableName); }
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); }
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); }
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); }
protected override MetaModel CreateModel(Type dataContextType) { return(new CustomMetaModel(mapping.GetModel(dataContextType), Shema)); }