zoukankan      html  css  js  c++  java
  • EF软删和删除 运用泛型

    public int Remove(int id)
    {
    T u1 = context.Set<T>().Find(id);
    //context.Set<T>().Remove(u1);
    //return context.SaveChanges();
    
    context.Entry(u1).Property("IsDelete").IsModified = true;
    context.Entry(u1).Property("IsDelete").CurrentValue = true;
    
    return 0;
    }
    
    public int Remove(int[] ids)
    {
    int counter = ids.Length;
    for (int i = 0; i < counter; i++)
    {
    //T u1 = context.Set<T>().Find(ids[i]);
    //context.Set<T>().Remove(u1);
    Remove(ids[i]);
    }
    //return context.SaveChanges();
    return 0;
    }
    

      

     1  Person p = new Person();
     2             p.Id = 1;
     3             p.Name = "张三";
     4             p.Sex = "";
     5             p.Weight = 65;
     6             p.Height = 180;
     7             p.Birthday = DateTime.Now;
     8 
     9             List<Person> pList = new List<Person>();
    10             pList.Add(p);
    11 
    12             List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
    13             foreach (var Entity in pList)
    14             {
    15                 Dictionary<string, object> row = new Dictionary<string, object>();
    16                 foreach (PropertyInfo item in Entity.GetType().GetProperties())
    17                 {
    18                     row.Add(item.Name, item.GetValue(Entity, null));
    19                 }
    20                 rows.Add(row);
    21             }
    22 
    23             var RealRows = rows.ToList();
    利用反射循环获取到实体实例化后的值
    NET新手,希望各位大侠多多指教。
  • 相关阅读:
    美团Java实习面试经历(拿到Offer)
    深受程序员鄙视的外行语录!
    3.7 操作数组的工具类-Arrays
    3.6 数组理解
    3.5 基本类型和引用类型变量
    3.4 Java数组类型
    3.3 break、continue、return结束循环结构
    3.2 循环结构
    3.1 Java分支结构
    2、Java运算符
  • 原文地址:https://www.cnblogs.com/duanyuerui/p/6962601.html
Copyright © 2011-2022 走看看