Syntax for inserting and updating using SqlCe and EntityFramework

VS 2008, SqlCe 3.5

I am trying to learn EntityFramework but cannot get the basic Insert and update to work. When I turn on the SqlCe database (.sdf), the wizard creates the file Test.edmx / designer.vb. From this, I create my datacontext as shown below. The table name is users.

The syntax of my entity classes is slightly different from the examples on the Internet. This is a bit confusing, and I don't know why that is. Below I show two different Insert methods, both of which throw exceptions on the .SaveChanges line:

An error occurred while updating the entries. See the InnerException for details.

{"Server keys and server-generated values ​​are not supported by SQL Server Compact."}

Also the Update method, which I really don’t know what to write in the missing part .. I would be very happy for your help on these issues ...

Public Sub Insert(ByVal user As Users)
    Dim ctx As New TestDBEntities1(connection)
    ctx.Users.Context.AddObject("Users", user)
    ctx.Users.Context.SaveChanges()
End Sub

Public Sub Insert(ByVal user As Users)
    Dim ctx As New TestDBEntities1(connection)

    ctx.AddToUsers(user)
    ctx.SaveChanges()
End Sub


Public Sub Update(ByVal user As Users)
    Dim ctx As New TestDBEntities1(connection)
    Dim q = (From n In ctx.Users Where n.Id = user.Id Select n).Single

    ' How to update ??

    ctx.SaveChanges()
End Sub
+3
2

; SQL CE 4.0.

0

Microsoft TechNet :

Entity Framework . . , . . "Store Generated" Entity Framework .

SQL Server Compact , Framework, Entity Framework . , " " .

, UNIQUEIDENTIFIER bigint/int. 1

+1

Source: https://habr.com/ru/post/1784219/


All Articles