private static IDataLayer GetDataLayer() { XpoDefault.Session = null; string conn = AccessConnectionProvider.GetConnectionString(@"|DataDirectory|\db.mdb"); XPDictionary dict = new DevExpress.Xpo.Metadata.ReflectionDictionary(); IDataStore store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.SchemaAlreadyExists); dict.GetDataStoreSchema(typeof(Order).Assembly); // <<< initialize the XPO dictionary IDataLayer dl = new ThreadSafeDataLayer(dict, store); return(dl); }
static ThreadSafeDataLayer CreateThreadSafeDataLayer(SqlConnection conn) { XPDictionary dict = new DevExpress.Xpo.Metadata.ReflectionDictionary(); IDataStore store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.SchemaAlreadyExists); //注意:如果项目中的XPO对象不是集中在一个类库而是分散在多个类库的话,我们需要在这里从每一个 // 类库中都任意抓取一个对象作为参数传递给 GetDataStoreSchema 方法 dict.GetDataStoreSchema( typeof(Hwagain.Components.BaseData).Assembly, typeof(YiKang.RBACS.AccessService).Assembly ); return(new ThreadSafeDataLayer(dict, store)); }
public static void Connect(DevExpress.Xpo.DB.AutoCreateOption autoCreateOption, bool threadSafe = false) { if (threadSafe) { var provider = XpoDefault.GetConnectionProvider(ConnectionString, autoCreateOption); var dictionary = new DevExpress.Xpo.Metadata.ReflectionDictionary(); dictionary.GetDataStoreSchema(persistentTypes); XpoDefault.DataLayer = new ThreadSafeDataLayer(dictionary, provider); } else { XpoDefault.DataLayer = XpoDefault.GetDataLayer(ConnectionString, autoCreateOption); } XpoDefault.Session = null; }
public static void Connect(IConfiguration configuration, DevExpress.Xpo.DB.AutoCreateOption autoCreateOption, bool threadSafe = false) { if (threadSafe) { var provider = GetConnectionProvider(configuration, autoCreateOption); var dictionary = new DevExpress.Xpo.Metadata.ReflectionDictionary(); dictionary.GetDataStoreSchema(persistentTypes); dictionary.CollectClassInfos(nonPersistentTypes); XpoDefault.DataLayer = new ThreadSafeDataLayer(dictionary, provider); } else { var provider = new OrmCookbookProvider(new SqlConnection(configuration.GetConnectionString(ConnectionStringName)), autoCreateOption); XpoDefault.DataLayer = new SimpleDataLayer(provider); } }