public List <Song> EfCoreSelect() { using (var db = new SongContext()) { return(db.Songs.Take(size).AsNoTracking().ToList()); } }
public void Setup() { Orm.fsql.CodeFirst.SyncStructure(typeof(Song), typeof(Song_tag), typeof(Tag)); //Orm.sugar.CodeFirst.InitTables(typeof(Song), typeof(Song_tag), typeof(Tag)); //sugar创建表失败:SqlSugar.SqlSugarException: Sequence contains no elements //测试前清空数据 Orm.fsql.Delete <Song>().Where(a => a.Id > 0).ExecuteAffrows(); //Orm.sugar.Deleteable<Song>().Where(a => a.Id > 0).ExecuteCommand(); Orm.fsql.Ado.ExecuteNonQuery("delete from efcore_song"); songs = Enumerable.Range(0, size).Select(a => new Song { Create_time = DateTime.Now, Is_deleted = false, Title = $"Insert_{a}", Url = $"Url_{a}" }); //预热 Orm.fsql.Insert(songs.First()).ExecuteAffrows(); //Orm.sugar.Insertable(songs.First()).ExecuteCommand(); using (var db = new SongContext()) { //db.Configuration.AutoDetectChangesEnabled = false; db.Songs.AddRange(songs.First()); db.SaveChanges(); } }
public int EfCoreInsert() { using (var db = new SongContext()) { //db.Configuration.AutoDetectChangesEnabled = false; db.Songs.AddRange(songs.ToArray()); return(db.SaveChanges()); } }