views:

55

answers:

3

I have a database that I have restored on SqlExpress from a bak file which was located on my SQL Server Pro instance. I am using Linq to interact with the database and am able to query and update some of my tables (i havent tried them all). However, I have at least one table that will not accept any kind of update (my UserAddress table). If I run this query

            TestDataContext td = new TestDataContext();
            UserAddress ua = (from u in td.UserAddresses
                              where u.UserID == 56
                              select u).Single();
            ua.Address1 = "ffffffffffffuuuuuuuuuuu";
            td.SubmitChanges();

nothing happens. No committed text in the database, no exception, nothing. This is my connection string (Data Source=SNEE\SQLEXPRESS;Initial Catalog=UsersDatabase;Integrated Security=True) although I have tried it with SQL Authentication and recieved the same result. Has anyone else ever experienced something like this? If so, what did you do to get it to work?

EDIT 1 After digging around in the desginer i noticed something odd. The address class looks like this

[Table(Name="dbo.UserAddress")]
public partial class UserAddress

however my user class looks like this

[Table(Name="dbo.User")]
public partial class User: INotifyPropertyChanging, INotifyPropertyChanged

I also noticed that the Extensibility Method Definitions are defined for User but not for UserAddress. What gives? Im sure this is the root of my problem but why did this occur. I tried to create a test datacontext and drag the table onto it again and it still wont create the necessary code.

A: 

Can you trace the query to see what L2S is generating? What does that query look like? Can you get an update to occur by executing that directly into SSMS?

Are there other outside influences? I have seen this issue before where a TRIGGER was preventing the update.

keithwarren7
A: 

try:

TestDataContext td = new TestDataContext();
            UserAddress ua = (from u in td.GetTable<UserAddresses>()
                              where u.UserID == 56
                              select u).Single();
            ua.Address1 = "ffffffffffffuuuuuuuuuuu";
            td.SubmitChanges();
kesun421
+1  A: 

I didn't have a primary key set for the table I was trying to update in my database instance. Linq, therefore, did not create the extensibility methods that handle the insert, update, and delete functions for that entity class. Thanks for replies.

jimbo