在VB.NET中找不到AddOrUpdate()方法
本文关键字:方法 AddOrUpdate 找不到 VB NET | 更新日期: 2023-09-27 18:02:03
我正在尝试将 c#代码转换为VB代码:
在c#代码中,它可以调用AddOrUpdate方法,但当我在VB中编写它时,它在智能感知中找不到。
c#代码: 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
我想你错过了
Imports System.Data.Entity.Migrations
因为AddOrUpdate()是一个扩展方法:AddOrUpdate方法的MSDN文章