tags:

views:

64

answers:

1

This is my query:

var query = (from v in _dataContext.UserInterests
                             join u in _dataContext.Users on v.UserId equals u.UserId
                             where u.Email.Equals(EmailAddress)
                             select v);


foreach (UserInterest reg in query)
{
    reg.Promotion = "1234-24323-1212";
    //other properties

    _dataContext.SubmitChanges()
}

No error is evoked, however when I look at my DB record, no changes are made. EmailAddress will become a comma separated value and hence the foreach loop above

Why does the above not throw an error but fails to update the db record.

The error I get is that invalid cast error. Prompotion is a varchar type in sql

Stack Trace:

 at System.Data.Linq.IdentityManager.StandardIdentityManager.SingleKeyManager`2.TryCreateKeyFromValues(Object[] values, V& v)
   at System.Data.Linq.IdentityManager.StandardIdentityManager.IdentityCache`2.Find(Object[] keyValues)
   at System.Data.Linq.IdentityManager.StandardIdentityManager.Find(MetaType type, Object[] keyValues)
   at System.Data.Linq.CommonDataServices.GetCachedObject(MetaType type, Object[] keyValues)
   at System.Data.Linq.ChangeProcessor.GetOtherItem(MetaAssociation assoc, Object instance)
   at System.Data.Linq.ChangeProcessor.BuildEdgeMaps()
   at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
   at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
   at System.Data.Linq.DataContext.SubmitChanges()
+1  A: 

Do you have a key field on the UserInterests object? Also check these:

http://stackoverflow.com/questions/86685/debugging-linq-to-sql-submitchanges

http://forums.asp.net/p/1223080/2187580.aspx

AUSteve
+2 yes, missing or incorrect PK in the model is the most likely cause
KristoferA - Huagati.com