Difference between revisions of "Databases Using Entity Framework"

From AdvancedHMI
Jump to: navigation, search
(SQL Server Interaction Using Entity Framework)
 
(2 intermediate revisions by the same user not shown)
Line 17: Line 17:
 
11) Give the name MyDbModel<br>
 
11) Give the name MyDbModel<br>
  
 
+
<code>
 
Using db As New LW5Entities
 
Using db As New LW5Entities
 
+
  Dim MyDbRecord As new MyDbTable
 +
  MyDbRecord.Field1="New test Record"
 +
  db.MyDbTables.Add(MyDbRecord)
 +
  db.SaveChanges
 
End Using
 
End Using
 +
</code>

Latest revision as of 17:31, 5 September 2016

SQL Server Interaction Using Entity Framework

The Entity Framework is currently Microsoft's recommended method of interacting with databases in the .NET framework. Performing a web search on Entity Framework will return a lot of tutorials and examples.

This Walk-Through will give a very simple example of the database first method. It is assumed an SQL Server Database already exists.

1) Open AdvancedHMI with Visual Studio
2) In Solution Explorer, right click the AdvancedHMI project and select Add->New Item (Ctrl+Shift+A)
3) In the left pane under Common Items, select Data
4) In the center pane select ADO.NET Entity Data Model
5) Give the name of MyDbModel and click the Add button
6) A Wizard will pop up. Select EF Designer from Database and click the Next button
7) Click the New Connection button
8) You will now need to enter the information related to your specific server and database instance
9) Click OK when finished selecting the database
10)
11) Give the name MyDbModel

Using db As New LW5Entities

  Dim MyDbRecord As new MyDbTable
  MyDbRecord.Field1="New test Record"
  db.MyDbTables.Add(MyDbRecord)
  db.SaveChanges

End Using