So, I've been playing around with EF and Sqlite. I've managed to in my dev environment get them successfully able to read and write "Hello world" from and to a database. I'm using as I said Entity framework and the sqlite entity framework provider.
I'm reading that EF needs to be run in a single threaded environment. That entirely confuses me because to my understanding, web apps service multiple requests in parallel. How can a utility that needs to be single threaded possibly hope to be used in a web server?
If it matters, here is the console app I'm using to play around with the connection -- It also represents my current sum experience with EF
class Program
{
static void Main(string[] args)
{
using (var context = new SessionContext("SessionTables.sqlite"))
{
var session = new Session()
{
SessionID = Guid.NewGuid().ToString("B"),
Domain = "NA",
Username = "Sidney",
Start = DateTime.UtcNow,
};
context.Sessions.Add(session);
var action = new UserAction()
{
ActionDescription = "Tested Entity Framework",
OccurredAt = DateTime.UtcNow,
};
session.Actions = new List<UserAction>();
session.Actions.Add(action);
context.SaveChanges();
}
}
}
public class Session
{
public string SessionID { get; set; }
public string Domain { get; set; }
public string Username { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
public virtual ICollection<UserAction> Actions { get; set; }
}
public class UserAction
{
public int UserActionID { get; set; }
public string ActionDescription { get; set; }
public DateTime OccurredAt { get; set; }
public Guid SessionID { get; set; }
public virtual Session Session { get; set; }
}
class SessionContext : DbContext
{
public SessionContext(string filename)
: base(new SQLiteConnection()
{
ConnectionString = new SQLiteConnectionStringBuilder()
{
DataSource = filename, ForeignKeys = true
}
.ConnectionString
}, true)
{ /**/ }
public DbSet<Session> Sessions { get; set; }
public DbSet<UserAction> Actions { get; set; }
}