Пример #1
0
 //The default constructor
 public UnitOfWork()
 {
     if (_service == null)
     {
         Define.ENTITYCONNSTRING = System.Configuration.ConfigurationManager.ConnectionStrings["VirtualTFSEntities"].ConnectionString;
         _service = new Entities(Define.ENTITYCONNSTRING);
     }
 }
Пример #2
0
        /// <summary>
        /// Gets the entity set for the specified entity in the specified object context.
        /// </summary>
        /// <param name="objectContext">The object context.</param>
        /// <param name="entityType">Type of the entity.</param>
        /// <returns>The entity set.</returns>
        public static EntitySet GetEntitySet(this ObjectContext objectContext, Type entityType)
        {
            Argument.IsNotNull("objectContext", objectContext);
            Argument.IsNotNull("entityType", entityType);

            var objectSet = GetObjectSet(objectContext, entityType);
            var entitySet = (EntitySet)PropertyHelper.GetPropertyValue(objectSet, "EntitySet", false);

            return(entitySet);
        }
        private static string GetTableName(System.Data.Objects.ObjectContext DB, Type entityType)
        {
            Type tableType    = typeof(System.Data.Objects.ObjectSet <>).MakeGenericType(entityType);
            var  propertyInfo = DB.GetType().GetProperties().Where(p => p.PropertyType.IsGenericType && p.PropertyType == tableType).FirstOrDefault();

            if (propertyInfo == null)
            {
                return(string.Empty);
            }
            return(propertyInfo.Name);
        }
Пример #4
0
        /// <summary>
        /// Gets the entity set for the specified entity in the specified object context.
        /// </summary>
        /// <param name="objectContext">The object context.</param>
        /// <param name="entityType">Type of the entity.</param>
        /// <returns>The entity set.</returns>
        public static object GetObjectSet(this ObjectContext objectContext, Type entityType)
        {
            Argument.IsNotNull("objectContext", objectContext);
            Argument.IsNotNull("entityType", entityType);

            var createObjectSetMethod        = objectContext.GetType().GetMethodEx("CreateObjectSet", new Type[] { });
            var genericCreateObjectSetMethod = createObjectSetMethod.MakeGenericMethod(entityType);

            var objectSet = genericCreateObjectSetMethod.Invoke(objectContext, new object[] { });

            return(objectSet);
        }
Пример #5
0
        public bool SaveChanges(System.Data.Objects.ObjectContext dataContext)
        {
            var dc = (WebContext)dataContext;

            if (this.EntityState == System.Data.EntityState.Detached)
            {
                dc.AddToFedExOdbiorcy(this);
            }
            dc.OptimisticSaveChanges();
            dc.Refresh(System.Data.Objects.RefreshMode.StoreWins, this);
            return(true);
        }
        public static string CreateMethods(MetadataResult metadata, System.Data.Objects.ObjectContext DB)
        {
            var sb = new StringBuilder(4096);

            metadata.dbSets.ForEach((dbSetInfo) =>
            {
                string tableName = GetTableName(DB, dbSetInfo.EntityType);
                if (tableName == string.Empty)
                {
                    return;
                }
                sb.AppendLine(createDbSetMethods(dbSetInfo, tableName));
            });
            return(sb.ToString());
        }
Пример #7
0
        /// <summary>
        /// Gets the name of the table.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="entityType">Type of the entity.</param>
        /// <returns>
        /// The table name including the schema.
        /// </returns>
        public static string GetTableName(this ObjectContext context, Type entityType)
        {
            Argument.IsNotNull("context", context);
            Argument.IsNotNull("entityType", entityType);

            return(_tableNameCache.GetFromCacheOrFetch(entityType, () =>
            {
                var objectSet = GetObjectSet(context, entityType);
                var methodInfo = objectSet.GetType().GetMethodEx("ToTraceString");
                var sql = (string)methodInfo.Invoke(objectSet, new object[] { });

                var regex = new Regex("FROM (?<table>.*) AS");
                var match = regex.Match(sql);

                string table = match.Groups["table"].Value;
                return table;
            }));
        }
Пример #8
0
        public static string CreateMethods(RunTimeMetadata metadata, System.Data.Objects.ObjectContext DB)
        {
            var sb = new StringBuilder(4096);

            var dbSets = metadata.DbSets.Values.OrderBy(d => d.dbSetName).ToList();

            dbSets.ForEach(dbSetInfo =>
            {
                string tableName = GetTableName(DB, dbSetInfo.GetEntityType());
                if (tableName == string.Empty)
                {
                    return;
                }

                sb.AppendLine(CreateDbSetMethods(dbSetInfo, tableName));
            });
            return(sb.ToString());
        }
Пример #9
0
 public bool SaveChanges(System.Data.Objects.ObjectContext dataContext)
 {
     if (dataContext != null && this.TowarGuid != Guid.Empty)
     {
         if (this.EntityState == System.Data.EntityState.Detached)
         {
             dataContext.AddObject("Magazyn_StanyMagazynowe", this);
         }
         dataContext.SaveChanges();
         dataContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, this);
         return(true);
     }
     if (this.EntityState == System.Data.EntityState.Added)
     {
         dataContext.DeleteObject(this);
     }
     return(false);
 }
Пример #10
0
        /// <summary>
        /// Dispose current context, transaction scope, set is_in_transaction flag to false
        /// </summary>
        public void Dispose()
        {
            if (_currentContext != null)
            {
                _currentContext.Dispose();
            }
            _currentContext = null;

            if (_transactionScope != null)
            {
                _transactionScope.Dispose();
            }
            _transactionScope = null;

            IsInTransaction = false;

            //CustomerIdentifier = null;
            //UserName = null;
            //Password = null;
            //ApiVersion = null;
            //ConnectionString = null;
        }
Пример #11
0
        protected void Application_Start()
        {
            //建立数据库
            Database.SetInitializer <OBContext>(new OBInitializer());

            using (var context = new OBContext())
            {
                System.Data.Objects.ObjectContext objcontext = ((IObjectContextAdapter)context).ObjectContext;
            }
            //调用WebSecurity的方法前需先调用InitializeDatabaseConnection初始化
            if (!WebSecurity.Initialized)
            {
                WebSecurity.InitializeDatabaseConnection("OB", "User", "Id", "Name", autoCreateTables: true);
            }

            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();
        }
Пример #12
0
 public OrderDetailRepository(System.Data.Objects.ObjectContext context)
     : base(context)
 {
 }
Пример #13
0
 public AddressService(System.Data.Objects.ObjectContext context)
 {
     this._addressRepository = new AddressRepository(context);
     base._repository        = this._addressRepository;
 }
Пример #14
0
 public DrawingsRepository(System.Data.Objects.ObjectContext context)
     : base(context)
 {
 }
Пример #15
0
 public PrizeCategoryService(System.Data.Objects.ObjectContext context)
 {
     this._prizecategoryRepository = new PrizeCategoryRepository(context);
     base._repository = this._prizecategoryRepository;
 }
Пример #16
0
 public RelUserRoleService(System.Data.Objects.ObjectContext context)
 {
     this._reluserroleRepository = new RelUserRoleRepository(context);
     base._repository            = this._reluserroleRepository;
 }
Пример #17
0
 public ContentService(System.Data.Objects.ObjectContext context)
 {
     this._contentRepository = new ContentRepository(context);
     base._repository        = this._contentRepository;
 }
Пример #18
0
 public PrizeCategoryRepository(System.Data.Objects.ObjectContext context)
     : base(context)
 {
 }
Пример #19
0
 public SysRoleRepository(System.Data.Objects.ObjectContext context)
     : base(context)
 {
 }
Пример #20
0
 public FreeCardService(System.Data.Objects.ObjectContext context)
 {
     this._freecardRepository = new FreeCardRepository(context);
     base._repository         = this._freecardRepository;
 }
Пример #21
0
 public AccountLogRepository(System.Data.Objects.ObjectContext context)
     : base(context)
 {
 }
Пример #22
0
 public BaseService(System.Data.Objects.ObjectContext context)
 {
     this._repository = new Repository <TEntity>(context);
 }
Пример #23
0
 public FriendLinkRepository(System.Data.Objects.ObjectContext context)
     : base(context)
 {
 }
Пример #24
0
 public ContentRepository(System.Data.Objects.ObjectContext context)
     : base(context)
 {
 }
Пример #25
0
 public AccountLogService(System.Data.Objects.ObjectContext context)
 {
     this._accountlogRepository = new AccountLogRepository(context);
     base._repository           = this._accountlogRepository;
 }
Пример #26
0
 public UserInfoRepository(System.Data.Objects.ObjectContext context)
     : base(context)
 {
 }
Пример #27
0
 public FriendLinkService(System.Data.Objects.ObjectContext context)
 {
     this._friendlinkRepository = new FriendLinkRepository(context);
     base._repository           = this._friendlinkRepository;
 }
Пример #28
0
 public RelRoleActionService(System.Data.Objects.ObjectContext context)
 {
     this._relroleactionRepository = new RelRoleActionRepository(context);
     base._repository = this._relroleactionRepository;
 }
Пример #29
0
 public ActionsRepository(System.Data.Objects.ObjectContext context)
     : base(context)
 {
 }
Пример #30
0
 public UserInfoService(System.Data.Objects.ObjectContext context)
 {
     this._userInfoRepository = new UserInfoRepository(context);
     base._repository         = this._userInfoRepository;
 }