Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ to SQL - Linq tries to insert column which doesn't exist
    text
    copied!<p>I created a simple database schema in Visual Studio and deployed to SQL Server. Then I created Linq-to-SQL mappings by dragging all the tables onto my model from the server explorer. </p> <p>After some time I decided to drop one column from the link table. I modified schema, removed database and deployed it again. I recreated my mappings by removing all entities from diagram and dragging all tables again. </p> <p>The problem is, that when I try to insert new entity to that table (on which I dropped my column), Linq-to-SQL still tries to insert a value there and that triggers a SQL Exception, saying that <code>Szkola</code> column name is invalid. I double checked entity diagram - no sign of <code>Szkola</code> column there and IntelliSense also doesn't show that <code>Szkola</code> might exist. But after inspecting generated SQL (after calling <code>.SubmitChanges()</code>):</p> <pre><code>INSERT INTO [dbo].[Uczen_Opiekun]([UczenPESEL], [OpiekunPESEL], [StopienPokrewienstwa], [Szkola]) VALUES (@p0, @p1, @p2, @p3) -- @p0: Input VarChar (Size = 8000; Prec = 0; Scale = 0) [10987654321] -- @p1: Input VarChar (Size = 8000; Prec = 0; Scale = 0) [12345678910] -- @p2: Input VarChar (Size = 8000; Prec = 0; Scale = 0) [ojciec] -- @p3: Input VarChar (Size = 8000; Prec = 0; Scale = 0) [Null] </code></pre> <p>I cleaned solution couple of times, removed and recreated mappings and database several times and nothing helped. Why this is happening and how to solve this issue?</p> <p><strong>EDIT 1:</strong></p> <p>I followed <strong>dasblinkenlight</strong> instructions and looked into *.dbml file via text editor. I found several occurences of <code>Szkola</code> column in other tables since it's a validation table, but in <code>Uczen_Opiekun</code> link table (which causes problem) I didn't find any <code>Szkola</code> references...</p> <pre><code>&lt;Table Name="dbo.Uczen_Opiekun" Member="Uczen_Opiekuns"&gt; &lt;Type Name="Uczen_Opiekun"&gt; &lt;Column Name="UczenPESEL" Type="System.String" DbType="VarChar(11) NOT NULL" IsPrimaryKey="true" CanBeNull="false" /&gt; &lt;Column Name="OpiekunPESEL" Type="System.String" DbType="VarChar(11) NOT NULL" IsPrimaryKey="true" CanBeNull="false" /&gt; &lt;Column Name="StopienPokrewienstwa" Type="System.String" DbType="VarChar(64)" CanBeNull="true" /&gt; &lt;Association Name="Opiekun_Uczen_Opiekun" Member="Opiekun" ThisKey="OpiekunPESEL" OtherKey="PESEL" Type="Opiekun" IsForeignKey="true" /&gt; &lt;Association Name="Uczen_Uczen_Opiekun" Member="Uczen" ThisKey="UczenPESEL" OtherKey="PESEL" Type="Uczen" IsForeignKey="true" /&gt; &lt;/Type&gt; &lt;/Table&gt; </code></pre> <h2><strong>Edit 2:</strong></h2> <p>Following suggestion from comments, I checked generated <code>Uczen_Opiekun</code> entity. There is no <code>Szkola</code> column, but still it's present in insert statement generated by Linq. Here is a short listing with fields generated from database schema.</p> <pre><code> [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Uczen_Opiekun")] public partial class Uczen_Opiekun : INotifyPropertyChanging, INotifyPropertyChanged { private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty); private string _UczenPESEL; private string _OpiekunPESEL; private string _StopienPokrewienstwa; private EntityRef&lt;Opiekun&gt; _Opiekun; private EntityRef&lt;Uczen&gt; _Uczen; (...) } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload