The application of the anti-DDoS principle and SQL in keywords in EF, sqlef
Suddenly realized the importance of words, so I began to write my first blog, with the goal of keeping a close record for ease of understanding.
At the same time, I also hope that the brick-and-mortar market can play a role in promoting mutual learning. You are welcome to express your thoughts and thoughts!
Background:
During the electronic fencing of Baidu map, the FenceUser field (Data Format:, 7) in the FenceUser field (Fence) in the FenceUser field of a Fence is directly updated, at the same time, update whether the FenceFlag (0 or 1) of the corresponding ID (1, 3, 7) of the User table is set to FenceFlag (0 or 1)
Therefore, we need to compare the Non-Public part of the corresponding ID value passed from the front-end and the corresponding ID value in the database, and then uniformly reverse the FenceFlag mark of the User table.
1 DBConn db = new DBConn(); 2 var fencelist = (from b in db.Fence.AsNoTracking() where b.fenceId == fenceID select b).ToList(); 3 string fenceusers = fencelist[0].fenceUsers; 4 string[] users = fenceusers.Split(','); 5 string[] arraymembers = ArraymembersToid.Split(','); 6 var listTemp = users.Concat(arraymembers).Except(users.Intersect(arraymembers)).ToList(); 7 var list = listTemp.Select<string, int>(q => Convert.ToInt32(q)); 8 var userFenceFlag = db.Users.Where(p => list.Any(a => a.Equals(p.id))).ToList(); 9 if (userFenceFlag.Count > 0)10 {11 foreach (Users user in userFenceFlag)12 {13 user.FenceFlag = -(user.FenceFlag - 1);14 }15 db.SaveChanges();16 17 }
View Code
Keywords:
Set
Intersect: intersection
Distinct T: difference set (A difference B refers to the differences between A and B, rather than all AB values)
Concat: Collection (all AB values, including duplicates)
EF
Any: similar to IN