I'm in the process of evaluating the dotConnect for SQLite Professional Version 3.30.165.0 (Trial License) with Visual Studio 2010 Professional with SP1 applied, and have written a simple console application that attempts to add a series of objects to the tables in my Entity Framework model, which was generated using the Model First approach.
Following the example in your Entity Framework Tutorial, specifically, the section entitled "Inserting New Data", I was able to create a simple C# .NET Console application that inserted the correct record values for each of the entities instantiated, and load the same entity values in the correct order using LINQ to Entity.
Although fairly straight-forward, to manually define each new entity instance's primary key value is not optimal. With this in mind, I am trying to leverage SQLite's ability to define and use Autoincrement Primary Key values. In short, I would like to be able to instantiate new entities and insert them into the database without having to explicitly know and define the new entity instance's primary key value before making and saving the changes through the ObjectContext subclass for my model.
With this in mind, can I let SQLite assign Primary Key values that are defined as Autoincrement and have entity instances inserted into the database where the model, the dotConnect SQLite ADO.NET provider, and the model generated entity classes can recognize and work with SQLite assigned primary keys? If so, how can this be done? Or, does the dotConnect SQLite provider only work with Entity Framework to add new entity instances to the database in which the Primary Key is explicitly defined when the model entity is instantiated for the first time?
Using the C# fragment below, can the Author, Genre, Book entity instances be added to the SQLite database genreated from the Entity Framework model if their respective primary keys are defined as Autoincrement?
Code: Select all
using (var context = new BookEntities())
{
var author = new Author()
{ FirstName = "Tim", LastName = "Dorsey" };
var genre = new Genre() { Category = "Fiction" };
var book1 = new Book()
{ Title = "Stingray Shuffle", YearPublished = 2003 };
author.Books.Add(book1);
genre.Books.Add(book1);
context.Authors.AddObject(author);
context.Genres.AddObject(genre);
context.Books.AddObject(book1);
context.SaveChanges();
}
Thank you in advance for your time and help.