public static void Delete() { context.Delete <User>(a => a.Id == 1); /* * DELETE FROM [Users] WHERE [Users].[Id] = 1 */ //批量删除 //删除所有不男不女的用户 context.Delete <User>(a => a.Gender == null); /* * DELETE FROM [Users] WHERE [Users].[Gender] IS NULL */ User user = new User(); user.Id = 1; context.Delete(user); /* * Int32 @P_0 = 1; * DELETE FROM [Users] WHERE [Users].[Id] = @P_0 */ ConsoleHelper.WriteLineAndReadKey(1); }
public static void DeleteTest() { string name = "so2"; //name = null; int r = -1; int?age = null; context.Session.BeginTransaction(); //r = context.Delete<User>(a => a.Gender == Gender.Man); r = context.Delete <User>(a => a.Age == 28); //r = context.Delete<User>(a => a.Gender == null); //r = context.Delete<User>(a => a.Age == age); //r = context.Delete<User>(a => age == a.Age); User user = new User(); user.Id = 16; r = context.Delete(user); context.Session.RollbackTransaction(); Console.WriteLine(1); }
/// <summary> /// 删除用户 /// </summary> /// <param name="userName">待删除的用户名</param> /// <returns>删除影响到的行数</returns> public int UserDelete(string userName) { return(context.Delete <User>(u => u.Name == userName)); }