protected void SetAbort() { DataContextAttribute dca = ExtractNestedContextAttribute(); if (dca == null) { return; } ContextManager.Instance.SetAbort(dca.ContextName); }
private DataContextAttribute ExtractNestedContextAttribute() { StackTrace stackTrace = new StackTrace(); StackFrame[] stackFrames = stackTrace.GetFrames(); foreach (StackFrame stackFrame in stackFrames) { MethodBase method = stackFrame.GetMethod(); object[] attrs = method.GetCustomAttributes(typeof(DataContextAttribute), false); if (attrs.Length > 0) { DataContextAttribute dca = attrs[0] as DataContextAttribute; return(dca); } } return(null); }
protected override void OnModelCreating(DbModelBuilder modelBuilder) { IEnumerable <Type> typesToRegister = GetType().Assembly.GetTypes() .Where(type => !String.IsNullOrEmpty(type.Namespace)) .Where( type => type.BaseType != null && type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() == typeof(DataEntityTypeConfiguration <>)); foreach (var type in typesToRegister) { DataContextAttribute dataContextAttribute = type.GetCustomAttribute <DataContextAttribute>(); if (dataContextAttribute == null || dataContextAttribute.Type == GetType()) { dynamic configurationInstance = Activator.CreateInstance(type); modelBuilder.Configurations.Add(configurationInstance); } } modelBuilder.Filter("SoftDeleteFilter", (ISoftDeletable d) => d.IsDeleted, false); }