Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
Infragistics & LINQ TO SQL: binding data across relationship
posted

Hi,

suppose you have two SQL tables that represent Users and related Location:

CREATE TABLE Users (

          ID   int IDENTITY (1,1)

          FirstName varchar(255)

          LastName varchar(255)

          ID_LOCATION int

         )

         

CREATE TABLE Locations(

          ID int IDENTITY (1,1)

         Name varchar (255)

         )

Suppose that there is a FK relation between Locations.ID and Users.ID_LOCATION.

Then I would like to create the following object:

MyDataContext dc = new MyDataContext()

var USER_LOCATION = from u IN dc.Users

select new

          {

                    u.ID,

                    u.FirstName,

                    u.LastName,

                    LocationName = u.Locations.Name  

          }

and use it as datasource for the Wingrid.

My problem is that when I try to do a SubmitChanges operation on the DataContext, I got no error but nothing is saved.

If I use a LNQ query that select a known class object, that's to say if I use a query like this:

var USERS_LOCATIONS2  = from u in dc.USERS select u;

Everything was saved succsessfully. Why?

In thi case, can I configure an unbound column to show data for "Locations.Name", exploiting he FK relation in some way ?

 

Thanks

         Denis Colla