Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I got what I wanted using the Entity Framework 4 with "code first". To write Objects from the classes I posted above, into the databse you just have to create the objects regulary:</p> <pre><code>Foo foo = new Foo(); foo.Woot = "foo1"; Foo foo2 = new Foo(); foo2.Woot = "foo2"; Bar bar = new Bar(); bar.name = "bar1"; bar.Whee = new List&lt;Foo&gt;(); bar.Whee.Add(foo); bar.Whee.Add(foo2); </code></pre> <p>Then create the <code>DbContext</code> object, add the other objects to this context and call saveChanges() method:</p> <pre><code>DBstructure dbconn = new DBstructure(); dbconn.Database.Connection.ConnectionString = connectionString //depends on your DB dbconn.Bars.Add(bar); dbconn.Database.Connection.Open(); dbconn.SaveChanges(); dbconn.Database.Connection.Close(); </code></pre> <p>That creates the new database with the tables "Foos" and "Bars" and another link table to manage the relations between the entitys.<br><br> Creating objects from the database information is also quite easy. Just connect to the database via the DbContext as it was done above. Create your objects and set them to the db data:</p> <pre><code>DBstructure dbconn = new DBstructure(); dbconn.Database.Connection.ConnectionString = connString; dbconn.Foos.ToList(); //seems that you have to do that dbconn.Bars.ToList&lt;Bar&gt;(); Bar barFromDB = new Bar(); barFromDB = dbconn.Bars.First&lt;Bar&gt;(); </code></pre> <p>That works fine in my application. Sorry for the strange class and variable names. I just copied the code from my test application. Hope that helps someone...<br><br> Grüßung Jucker!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload