I have a very interesting problem on my LinqToSql model. On some of my tables i have a references to other tables and in LinqToSql this is represented by a EnitiyRef class, when you are trying to access the references table LinqToSql will load the reference from the database.
On my development machine everything worked fine (the references were loaded perfectly) but last night i uploaded the changed to our production server and started getting NullReferenceExceptions when trying to access the reference on my tables.
Sample code:
var sale = db.Sales.Single(s => s.ID == 1);
string username = sale.User.Name; // User is a reference to a User table
// LinqToSql will automatically load the
// row and access the fields i need.
// On my server the sale.User throws an exception that its null (User) but the user
// is definitly in the database (there is even a FK constraint from Sale to User)
At first i thought that it my DataContext got GC'd but i double checked everything with no result (besides it works on my box).
(Everything is the same on the server and my box, same dll's, same db schema etc...) (I actually copied the entire DBF file over to my server so its the exact same schema)