I have the following class defined in F #, with display attributes for Linq to SQL:
[<Table(Name="Expense")>]
type public Expense(datetime : Nullable<DateTime>, 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
[<Column(IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.OnInsert)>]
member x.ExpenseID with get() = id and set v = id <- v
[<Column>]
member x.DateTime with get() = datetime and set v = datetime <- v
[<Column>]
member x.Value with get() = value and set v = value <- v
[<Column>]
member x.Category with get() = category and set v = category <- v
[<Column>]
member x.Comment with get() = comment and set v = comment <- v
new() = Expense(nl, 0m, "", "")
Then I want to insert a new object of this type using the following code (snippet):
member private x.expenses = (new DataContext(connString)).GetTable<Expense>()
member x.Add (expense : Expense) =
x.expenses.InsertOnSubmit(expense)
x.expenses.Context.SubmitChanges()
A call to the SubmitChanges () method does nothing, and no exception is thrown. So I tried to check if there is something that is an F # object, and I declared another class in C # with exactly the same mappings. Then I was able to insert a new record. Now I wonder what's the difference?
Was there some kind of reflector research, the only difference was the [CompilerGenerated] attributes on C # autocaptures / setters and [Serializable] and CompilationMapping (SourceConstructFlags.ObjectType)] in the F # class ... could this be one of those?
: http://pastebin.com/qTRfVcmm
//EDIT
.NET, , DataContext InsertOnSubmit SubmitChanges. SubmitChanges . , DataContext, VS . , , .