Answer the question
In order to leave comments, you need to log in
How to remove element from DbContext Entity Framework?
Good afternoon!
Please advise how to fix the following situation. There is a BookContext db (DbContext), which is already connected to the table of the same name in the Oracle database. New entries from the code are added perfectly, i.e. line
db.Books.Add(new Book { Name = "First step", Author = "shavadre", Price = 120 })
Book delBook = db.Books.Where(x => x.Id == 2).FirstOrDefault();
db.Books.Remove(delBook);
db.SaveChanges();
[Table("BOOKS",Schema="VRSHAIKHISLAMOV")]
public class Book
{
[Column("ID", TypeName="NUMBER")]
[Required]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Column("NAME", TypeName="VARCHAR2")]
public string Name { get; set; }
[Column("AUTHOR", TypeName = "VARCHAR2")]
public string Author { get; set; }
[Column("PRICE", TypeName = "NUMBER")]
public int Price { get; set; }
}
public class BookContext : DbContext
{
public DbSet<Book> Books { get; set; }
}
Answer the question
In order to leave comments, you need to log in
Book delBook = db.Books.Where(x => x.Id == 2).FirstOrDefault();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question