Beispiel #1
0
        public XafHelper(IUnityContainer unityContainer, string connectionString = null)
        {
            if (connectionString == null)
            {
                connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            }

            foreach (var type in Types)
            {
                XafTypesInfo.Instance.RegisterEntity(type);
            }

            var typesInfoSource = new XpoTypeInfoSource(XafTypesInfo.Instance as TypesInfo);

            foreach (var type in Types)
            {
                typesInfoSource.RegisterEntity(type);
            }

            _ObjectSpaceProvider = new UnityXPObjectSpaceProvider(new ConnectionStringDataStoreProvider(connectionString), XafTypesInfo.Instance, typesInfoSource, unityContainer, true);

            using (var objectSpace = _ObjectSpaceProvider.CreateUpdatingObjectSpace(false))
            {
                var xpObjectSpace = objectSpace as XPObjectSpace;
                if (xpObjectSpace != null)
                    xpObjectSpace.Session.CreateObjectTypeRecords();
            }
        }
Beispiel #2
0
        public XafHelper(IUnityContainer unityContainer, string connectionString = null)
        {
            if (connectionString == null)
            {
                connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            }

            foreach (var type in Types)
            {
                XafTypesInfo.Instance.RegisterEntity(type);
            }

            var typesInfoSource = new XpoTypeInfoSource(XafTypesInfo.Instance as TypesInfo);

            foreach (var type in Types)
            {
                typesInfoSource.RegisterEntity(type);
            }

            _ObjectSpaceProvider = new UnityXPObjectSpaceProvider(new ConnectionStringDataStoreProvider(connectionString), XafTypesInfo.Instance, typesInfoSource, unityContainer, true);

            using (var objectSpace = _ObjectSpaceProvider.CreateUpdatingObjectSpace(false))
            {
                var xpObjectSpace = objectSpace as XPObjectSpace;
                if (xpObjectSpace != null)
                {
                    xpObjectSpace.Session.CreateObjectTypeRecords();
                }
            }
        }
Beispiel #3
0
        public static void DeleteAllData(this IObjectSpaceProvider objectSpaceProvider)
        {
            using var objectSpace = objectSpaceProvider.CreateUpdatingObjectSpace(true);
            var dbConnection =
                ((ConnectionProviderSql)((BaseDataLayer)((XPObjectSpace)objectSpace).Session.DataLayer)
                 .ConnectionProvider).Connection;

            DeleteAllData(dbConnection);

            objectSpaceProvider.UpdateSchema();
        }
Beispiel #4
0
        public static void DeleteAllData(this IObjectSpaceProvider objectSpaceProvider)
        {
            using (var objectSpace = objectSpaceProvider.CreateUpdatingObjectSpace(true)){
                var dbConnection = ((ConnectionProviderSql)((BaseDataLayer)((XPObjectSpace)objectSpace).Session.DataLayer).ConnectionProvider).Connection;
                using (var dbCommand = dbConnection.CreateCommand()){
                    dbCommand.CommandText = @"
        EXEC sp_MSForEachTable ""ALTER TABLE ? NOCHECK CONSTRAINT all""
        EXEC sp_MSForEachTable ""DELETE FROM ?""
        exec sp_MSForEachTable ""ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all""
";
                    dbCommand.ExecuteNonQuery();
                }
                objectSpaceProvider.UpdateSchema();
            }
        }