Thursday, October 27, 2011

Cannot implicitly convert type 'System.Data.Objects.ObjectResult' to 'int?'

When you're executing a Save on your DataContext using EF, and get this error:

Cannot implicitly convert type 'System.Data.Objects.ObjectResult' to 'int?'

You may want to try adding a SingleOrDefault or FirstOrDefault to the end of your SPROC call to close the transaction before you save.

BAD
int? rc = myContext.myProc(myParameter);
myContext.Save();

GOOD
int? rc = myContext.myProc(myParameter).FirstOrDefault();
myContext.Save();

No comments:

Post a Comment