//public static List<T> GetListOf<T>(Expression<Func<T, bool>> expression) where T : class //{ // using (PermaisuriCMSEntities db = new PermaisuriCMSEntities()) // { // return db.Set<T>().Where(expression).ToList(); // } //} //public static List<T> GetListOf<T>(Expression<Func<T, bool>> expression) where T : class //{ // ProductsEntities _context = new ProductsEntities(); // return _context.CreateObjectSet<T>().Where(expression).ToList(); //} /// <summary> /// 这个方法用户记录数据库所有产生变化的字段,方便迅捷,但是缺点就是像ID这样的字段,只能记录ID不能记录名称,不方面前端知直接查看: /// 比如:[ColourID] : old value = 307 , new Value = 304,另外对于强类型新增的对象的ID,记录为0.... /// 2014年3月10日 /// </summary> /// <param name="table"></param> /// <param name="logDetail"></param> public static void DbRecorder(DbEntityEntry table, LogOfUserOperatingDetails logDetail) { var logDesc = string.Empty; var entry = table; var currentPropertyNames = entry.CurrentValues.PropertyNames;//OriginalValues var modifiedProperties = from name in currentPropertyNames where entry.Property(name).IsModified select name; foreach (var propertyName in modifiedProperties) { logDesc += " <b> [" + propertyName + "] </b> : old value = <span style='color:red'> " + HttpUtility.HtmlEncode(entry.OriginalValues[propertyName]) + " </span> , new Value = <span style='color:red'> " + HttpUtility.HtmlEncode(entry.CurrentValues[propertyName]) + " </span>"; logDesc += "<br>"; } logDetail.Descriptions = logDesc; DbRecorder(logDetail); }
/// <summary> /// 这个方法不解释... /// </summary> /// <param name="logDetail"></param> public static void DbRecorder(LogOfUserOperatingDetails logDetail) { IDictionary <string, string> ls = new Dictionary <string, string>(); ls.Add("ModelName", logDetail.ModelName); ls.Add("ActionName", logDetail.ActionName); ls.Add("ActionType", logDetail.ActionType.ToString(CultureInfo.InvariantCulture)); ls.Add("SKU", logDetail.SKU); ls.Add("SKUID", logDetail.SKUID.ToString()); ls.Add("ChannelID", logDetail.ChannelID.ToString()); ls.Add("ChannelName", logDetail.ChannelName); ls.Add("ProductID", logDetail.ProductID.ToString()); ls.Add("HMNUM", logDetail.HMNUM.ToString(CultureInfo.InvariantCulture)); ls.Add("Descriptions", logDetail.Descriptions); ls.Add("CreateOn", logDetail.CreateOn.ToString("yyyy-MM-dd HH:mm:ss")); ls.Add("CreateBy", logDetail.CreateBy); NBCMSLoggerManager.NBCMSLogger("OperatingDetail", "", ls); }