June 28, 2014
windows phone LINQ "already exists" issue on empty table
Update this happens not only when you have the only primary key field. Even when primary key is autogen, this exception happens when you put same value as you deleted previously in same DataContext session. I don't have workaround yet. Do you?
LINQ to SQL has strange effects when you try to reuse DataContext (re-creating of DataContext after every update/delete operation has different bad effect).
For example if your sole field is actually your primary key (it is unique at any moment and not null) and you delete it and in the same DataContext session insert same value, you will have InvalidOperationException. In my case the table is even empty!
[Table(Name = "Receipts")] public class Receipt : PropertyChangedBase { protected String _s; public Receipt() { } public Receipt(String s) { _s = s; } [Column(IsPrimaryKey = false, CanBeNull = false, AutoSync = AutoSync.Always)] public String sIt seems that after delete you have to recreate DataContext. Will try this strategy.
Labels: c#, development, linq, microsoft, programming, sql, windows phone, wisual studio