我正在尝试将 C#代码转换为VB代码 :
在C#代码中,它可以调用AddOrUpdate方法,但是当我在VB中编码时,它在intellisense中找不到。
c#code:
protected override void Seed(eManager.Web.Infrastructure.DepartmentDB context){
context.Departments.AddOrUpdate( d => d.Name,
new Department() { Name = "Engineering"},
new Department() { Name = "Sales"}
);
}
VB代码:
但是当我用VB编写方法AddOrUpdate()时,我找不到它。 DepartmentDB类的声明是这样的:
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Data.Entity
Imports eManager.Domain
Public Class DepartmentDB
Inherits DbContext
Implements IDepartmentDataSource
Private _DBEmployees As DbSet(Of Employee)
Private _DBDepartments As DbSet(Of Department)
Public ReadOnly Property Departments As IQueryable(Of Department) Implements IDepartmentDataSource.Departments
Get
Return _DBDepartments
End Get
End Property
Public ReadOnly Property Employees As IQueryable(Of Employee) Implements IDepartmentDataSource.Employees
Get
Return _DBEmployees
End Get
End Property
End Class
答案 0 :(得分:7)
我认为你错过了
Imports System.Data.Entity.Migrations
因为AddOrUpdate()是一个扩展方法: MSDN article for AddOrUpdate method