我是EF core 2.0的新用户我反向设计了我的数据库,现在有了一个dbContext文件和我所有的模型类。我正在尝试使用linq查询EF但无法访问Where子句?有人能指出我做错了吗?是否有我应该使用的System.Linq以外的命名空间?
这就是我要做的事。
var foundObjects = _contextMarketing.T_CustomerCampaigns.Where(o => o.CheckNum.Equals(prospect.offerCode))。ToList();
答案 0 :(得分:0)
如果您Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.IO
Imports System.IO.FileInfo
<Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute()>
<System.CLSCompliantAttribute(False)>
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
Protected Sub SaveFile(ByVal url As String, ByVal localpath As String)
Dim loRequest As System.Net.HttpWebRequest
Dim loResponse As System.Net.HttpWebResponse
Dim loResponseStream As System.IO.Stream
Dim loFileStream As New System.IO.FileStream(localpath, System.IO.FileMode.Create, System.IO.FileAccess.Write)
Dim laBytes(256) As Byte
Dim liCount As Integer = 1
Try
loRequest = CType(System.Net.WebRequest.Create(url), System.Net.HttpWebRequest)
loRequest.Credentials = System.Net.CredentialCache.DefaultCredentials
loRequest.Timeout = 600000
loRequest.Method = "GET"
loResponse = CType(loRequest.GetResponse, System.Net.HttpWebResponse)
loResponseStream = loResponse.GetResponseStream
Do While liCount > 0
liCount = loResponseStream.Read(laBytes, 0, 256)
loFileStream.Write(laBytes, 0, liCount)
Loop
loFileStream.Flush()
loFileStream.Close()
Catch ex As Exception
End Try
End Sub
Public Sub Main()
Dim url, destination, newname As String
destination = Dts.Variables("Folder_Destination").Value.ToString + "\" + Dts.Variables("FileName").Value.ToString + ".xpdf"
url = "http://localhost/reportserver?/PDFExport/DEVOrderPDF&rs:Command=Render" + Dts.Variables("FileName").Value.ToString + "&rs:Format=PDF"
SaveFile(url, destination)
newname = Path.GetFileNameWithoutExtension(destination) + ".pdf"
My.Computer.FileSystem.RenameFile(destination, newname)
Dts.TaskResult = ScriptResults.Success
End Sub
End Class
生成了文件,那么您应该没有问题。 https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db
如果你这样做了,你应该拥有的是一堆模型类,如:
Scaffold-DbContext
然后是类似于此的public partial class SomeTable
{
public int SomeValue {get;set;}
}
类:
Context
然后你的电话应该是public partial class SomeContext : DbContext
{
public virtual DbSet<SomeTable> SomeTable { get; set; }
....
}
。
我认为您没有完成脚手架调用,而是在您的someContext.SomeTable.Where(...)
DbSet<...>
属性