I'm using EF in order to insert simple object into db:
public bool AddQuestion(Question question)
{
try
{
_ctx.Questions.Add(question);
_ctx.SaveChanges();
return true;
}
catch(Exception ex)
{
return false;
}
}
my DbContext look like:
public class AnyContext:DbContext
{
public AnyContext():base()
{
Configuration.ProxyCreationEnabled = false;
Configuration.LazyLoadingEnabled = false;
Database.SetInitializer(new MigrateDatabaseToLatestVersion<AnyContext, AnyContextMigrationConfiguration>());
}
public AnyContext(string connectionString)
: base(connectionString)
{
Configuration.ProxyCreationEnabled = false;
Configuration.LazyLoadingEnabled = false;
Database.SetInitializer(new MigrateDatabaseToLatestVersion<AnyContext, AnyContextMigrationConfiguration>());
}
public DbSet<Question> Questions { get; set; }
}
And POCO look like:
[Table("Questions")]
public class Question
{
public int Id { get; set; }
public String body { get; set; }
public String img_path { get; set; }
public int location { get; set; }
public int status { get; set; }
public DateTime ask_date { get; set; }
}
And I get *"Store update, insert, or delete statement affected an unexpected number of rows (0). * every time
What am I doing wrong?