Ejemplo n.º 1
0
            internal DynamicAttributedMetaModel(MappingSource mappingSource, Type contextType)
            {
                this.mappingSource = (DynamicMappingSource)mappingSource;
                var bf   = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance;
                var args = new object[] { mappingSource, contextType };

                source = typeof(DataContext).Assembly.CreateInstance(TypeName, false, bf, null, args, CultureInfo.CurrentCulture, null) as MetaModel;
                Debug.Assert(source != null);
            }
Ejemplo n.º 2
0
 /// <summary>
 /// 初始化数据库上下文
 /// </summary>
 /// <param name="connectionString">数据库连接</param>
 /// <param name="mapping">动态DynamicMappingSource</param>
 public SqlDataContext(string connectionString, DynamicMappingSource mapping)
     : base(connectionString, mapping)
 {
     mapping.GetMetaTableName = delegate(Type type)
     {
         string         tableName;
         TableAttribute attr = type.GetCustomAttributes(typeof(TableAttribute), true).Single() as TableAttribute;
         tableName = attr.Name;
         if (!string.IsNullOrEmpty(this.TablePrefix))
         {
             tableName = this.TablePrefix + tableName;
         }
         return(tableName);
     };
 }