publicoverrideIEnumerable<MetaFunction>GetFunctions()
{
returnsource.GetFunctions();
}
publicoverrideMetaTypeGetMetaType(Typetype)
{
returnsource.GetMetaType(type);
}
publicoverrideMappingSourceMappingSource
{
get{returnsource.MappingSource;}
}
publicoverrideTypeContextType
{
get{returnsource.ContextType;}
}
publicoverridestringDatabaseName
{
get{returnsource.DatabaseName;}
}
publicoverrideTypeProviderType
{
get{returnsource.ProviderType;}
}
}
publicFunc<Type,string>GetMetaTableName;
protectedoverrideMetaModelCreateModel(TypedataContextType)
{
if(dataContextType==null)
{
thrownewArgumentNullException("dataContextType");
}
returnnewDynamicAttributedMetaModel(this,dataContextType);
}
}
[Table(Name="User")]
classUser
{
[Column]
publicintID;
[Column]
publicstringName;
}
classProgram
{
staticvoidMain(string[]args)
{
varmappingSource=newDynamicMappingSource();
inti=0;
mappingSource.GetMetaTableName=delegate(Typetype)
{
varatt=type.GetCustomAttributes(typeof(TableAttribute),true).Single()
asTableAttribute;
Debug.Assert(att!=null);
returnatt.Name+i;
};
varconstr=@"DataSource=NOTEBOOKSQLEXPRESS;InitialCatalog=DemoDataContext;IntegratedSecurity=True";
varcontext=newDataContext(constr,mappingSource){Log=Console.Out};
i=1;
context.GetTable<User>().Select(o=>o).ToList();
i=2;
context.GetTable<User>().Select(o=>o).ToList();
}
}
}
责任编辑:小草