I need to use a transaction in Entity Framewok (version 5) in a controller of an MVC4 project. This because I've to save data in different table within the same transaction and avoid data inconsistency..
using System;
using System.Collections.Generic;
using System.Linq; using System.Web.Mvc;
using System.IO;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Data;
using System.Data.Objects;
private DBcontextName context = new DBcontextName ();
context.Connection.Open();
When i try to use transaction, the object Connection is not recognized by context
DbContext does not contain a definition for 'Connection' and no extension method 'Connection' accepting a first argument of type...
I don't understand what it's wrong, can you help me please?
namespace NameSpaceName {
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Linq;
public partial class DBcontextName : DbContext
{
public DBcontextName ()
: base("name=DBcontextName ")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet......{ get; set; }
public DbSet......{ get; set; }
}
}
Thanks