I had an existing application using Linq To SQL linked to a LocalDB mdf.
The MDF is located in the main project folder.
I also copied the MDF to the bin folder, which is what the app uses when debugging from VS.
I've confirmed in SQL Server Management Studio that the field exists in both MDFs.
I used a DBML/EDMX tool to update my Linq Diagram to reflect the added column.
I also confirmed the field is properly shown in the database.designer.vb class.
But, when I run the app from VS and run a LINQ query on the entire table
Dim ticketsForBatch = From ticket In BatchTickets.MemberPanTickets _
Order By ticket.BatchID
Where ticket.BatchID = _currentBatchId
I get this error: Invalid column name 'BillTo'.
BillTo is the column I added. That linq query worked fine before adding the new column.
I'm stumped. The field seems to exist in the underlying database, the LINQ Diagram, and the LINQ class.
What could be causing this?
Drilling further, I expanded the MemberPanTicket variable and got this as the SQL the LINQ creates:
SELECT [t0].[TicketID], [t0].[TicketNbr], [t0].[BatchID], [t0].[LocationID], [t0].[TicketDt], [t0].[Bottle], [t0].[EnteredDt], [t0].[ExcelDt], [t0].[SSMA_TimeStamp], [t0].[CommodityID], [t0].[BillTo], [t0].[Other], [t0].[WC], [t0].[BL], [t0].[RailCar], [t0].[Lot], [t0].[General], [t0].[Sta], [t0].[DoGrade], [t0].[DoProtein], [t0].[DoFalling], [t0].[DoMalt], [t0].[DoOther]
FROM [dbo].[MemberPanTickets] AS [t0]
WHERE [t0].[BatchID] = 27
ORDER BY [t0].[BatchID]
I copied that sql to Management Studio and ran it against the MDF the app is using.
I also confirmed the app is pointing to the right mdf by renaming the mdf and running the app. It gave a compile error for not finding the mdf. So, it's definitely pointing to the right database.
So, there must be something wrong with the Linq code that ties the Linq class to the actual table.
How do I track down that code?
EDIT: More info...
Here's the mapping code in PanTickets.designer.vb:
<Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_BillTo", DbType:="NVarChar(5)", UpdateCheck:=UpdateCheck.Never)> _
Public Property BillTo() As String
Set(value As String)
If (String.Equals(Me._BillTo, Value) = False) Then
Me._BillTo = Value
It looks the same, structurally, as the other fields in designer.
Does any of that help?