• 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新手,希望各位大侠多多指教。
  • 相关阅读:
    http
    python的列表生成式
    flask的登陆验证
    脚本更新流程
    k8s中job和pod的区别
    k8s中一些常见概念
    supervisord部署和使用
    flask中config
    python类的继承super()的使用
    python中类的继承
  • 原文地址:https://www.cnblogs.com/duanyuerui/p/6962601.html
Copyright © 2020-2023  润新知