Note that there are some explanatory texts on larger screens.

plurals
  1. POF# Linq To SQL commiting changes doesn't do anything
    text
    copied!<p>I've got following class defined in F#, with mapping attributes for Linq to SQL:</p> <pre><code>[&lt;Table(Name="Expense")&gt;] type public Expense(datetime : Nullable&lt;DateTime&gt;, value, category, comment) = let mutable id = 0 let mutable datetime = if datetime.HasValue then datetime.Value else DateTime.Now let mutable value = value let mutable category = category let mutable comment = comment [&lt;Column(IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.OnInsert)&gt;] member x.ExpenseID with get() = id and set v = id &lt;- v [&lt;Column&gt;] member x.DateTime with get() = datetime and set v = datetime &lt;- v [&lt;Column&gt;] member x.Value with get() = value and set v = value &lt;- v [&lt;Column&gt;] member x.Category with get() = category and set v = category &lt;- v [&lt;Column&gt;] member x.Comment with get() = comment and set v = comment &lt;- v new() = Expense(nl, 0m, "", "") </code></pre> <p>Then I want to insert new object of that type, using following code (fragment):</p> <pre><code>member private x.expenses = (new DataContext(connString)).GetTable&lt;Expense&gt;() member x.Add (expense : Expense) = x.expenses.InsertOnSubmit(expense) x.expenses.Context.SubmitChanges() </code></pre> <p>Calling SubmitChanges() doesn't do anything, nor any exception is thrown. So I tried to check, if there is something with it being an F# object, and I've declared other class in C#, with exactly same mappings. Then I was able to insert new record. Now I'm wondering, what's the difference?</p> <p>Did some Reflector investigation, the only difference are attributes [CompilerGenerated] on C# auto getters/setters, and [Serializable] and CompilationMapping(SourceConstructFlags.ObjectType)] on F# class...could it be one of those?</p> <p>Reflector disassemblies: <a href="http://pastebin.com/qTRfVcmm" rel="nofollow">http://pastebin.com/qTRfVcmm</a></p> <p>// EDIT</p> <p>By doing some debugging against .NET framework code, I've noticed that internal list of tracked objects of the DataContext instance is not consistent between InsertOnSubmit and SubmitChanges call. At the beginning of the SubmitChanges call, this list is empty. That led me to thinking, those two references are not targeting same DataContext instance, and VS debugger confirmed that. Still, no idea why.</p>
 

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