我有一些旧的SQL代码在从数据库查询时使用左连接。我不知道如何使用EF做到这一点,但我可以想象它更简单。 (VB.NET最新版本)
这是SQL代码:
'Now Change each of the dimension values on the EDD stack to EDD dimension Values
' - if Not deleted And on the stack
SqlString = "SELECT * FROM StackUp " +
"LEFT JOIN StackUpItems On IdStackUp=StackUpID " +
"LEFT JOIN DimensionValues ON DimensionValuesId=IdDimensionvalues " +
"WHERE IdStackUp=" + StackUpId.ToString + " AND " +
"isnull(IsDimensionValuesDeleted,0)=0 AND isnull(StackUpItems.IsDeleted,0)=0 ;"
SqlDataAdapter = New SqlDataAdapter(SqlString, SqlConnectionString)
TableNow = New DataTable
SqlDataAdapter.Fill(TableNow)
我尝试过一些东西,但是当我谈到这些类型的查询时,我不知道我在做什么。
以下是我的数据库对象的代码:
Function ToggleIsEDD(ByVal StackUpId) As Boolean
'main try
Try
Dim IdNow As Integer = StackUpId
Dim StackUpNow As IEnumerable(Of Stackup) = (From a In Db.Stackup Where a.IdStackup = IdNow).ToList
答案 0 :(得分:0)
以下是我的工作:
''Now Change each of the dimension values on the EDD stack to EDD dimension Values
'' - if Not deleted And on the stack
'================================================================
'This might need "or not null" statements within query as well
'================================================================
StackUpNow = (From a In Db.StackupItems
Where a.IdStackupItem =
IdNow And Not a.Stackup.IsDeleted And Not a.DimensionValues.IsDimensionValuesDeleted
).ToList