0

In my project I've two Interesting database tables:

CREATE TABLE [dbo].[User]
(
  [Id] INT NOT NULL IDENTITY, 
  [Name] NCHAR(60) NOT NULL, 
  PRIMARY KEY ([Id])
)

CREATE TABLE [dbo].[Event]
(
  [Id] INT NOT NULL PRIMARY KEY identity,
  ...  
  [User id] INT NULL,
  CONSTRAINT [FK_Event_User] FOREIGN KEY ([User id]) REFERENCES [User](Id)
)

I want to have access to the Event's users in my Application which take data from WCF.

To make this possible I've to change Child Property in User_Event Association according to this answer.

I use LINQ SQL and I noticed that event.User property is not null only when I invoke get properties on it.

Now I have to add for loop to force invoking this._User.Entity, but it don't look like this solution...

    public List<Event> GetAllEvents()
    {
        var ev = Database.Instance.Db.Events;
        foreach (var v in ev)
        {
            User u = v.User;
        }
        return ev.ToList();
    }
Community
  • 1
  • 1
Jakub Kuszneruk
  • 1,188
  • 1
  • 12
  • 37

1 Answers1

0

Probably the problem was caused by DataContext.DeferredLoadingEnabled Property.

According to msdn:

DeferredLoadingEnabled

Gets or sets a value that indicates whether to delay-load one-to-many or one-to-one relationships.

update

finally I've solved this problem with LoadWith function from Linq to SQL.

db = new ModelDataContext();

/* setting lazy evaluation rules */
DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith((Session s) => s.Exam);
dlo.LoadWith((Session s) => s.SessionUsers);
db.LoadOptions = dlo;
Community
  • 1
  • 1
Jakub Kuszneruk
  • 1,188
  • 1
  • 12
  • 37