I have a strange problem with entity framework, In my project im using EF 6 codefirst and for my database im using sqlserver 2012
as with a table iam using isactive column of type bit, which represents 0 or 1 only. and defaultly i kept this column value as 1 which is represents true.
When we want to delete a record from the table we should have to make 1 to 0, but the entity framework doesn't updating the value.
is any one having this strange problem any 1 with solution here ??
Code:
using (var context = new TriviaContext())
{
var booking = context.Booking.FirstOrDefault(b => b.BookingId == id);
context.Entry(booking).Property(u => u.IsActive).IsModified=true;
booking.IsActive = false;
context.SaveChanges();
return Ok(booking);
}
Booking Model:
class Booking
{
public int BookingId { get; set; }
public string Name{get;set;}
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public bool? IsActive { get; set; }
}
edit: actually i have included DatabaseGenerated Attribute in my model class, may be this is causing the problem ?
TriviaContext:
public class TriviaContext : DbContext
{
public TriviaContext()
: base("name=DefaultConnection")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
public DbSet<Bookings> Booking { get; set; }
}
TrivaContext
code? This works fine for me