| Using context As New MyDbContext() |
| ' 添加数据 |
| Dim newEntity As New MyEntity() With { |
| .Name = "Example Name" |
| ' 设置其他属性... |
| } |
| context.MyEntities.Add(newEntity) |
| context.SaveChanges() |
| |
| ' 查询数据 |
| Dim entities = context.MyEntities.ToList() |
| |
| ' 更新数据 |
| Dim firstEntity = context.MyEntities.First() |
| firstEntity.Name = "Updated Name" |
| context.SaveChanges() |
| |
| ' 删除数据 |
| context.MyEntities.Remove(firstEntity) |
| context.SaveChanges() |
| End Using |