fetching with linq

fetching with linq

Old forum URL: forums.lhotka.net/forums/t/5100.aspx


dmeadowcroft posted on Tuesday, July 15, 2008

I have a few months of working with .net, csla and c# but making great progress. looking for anyone to address some new code an tell me if there is any possible negatives to this approach.. thanks in advance..

I replace the following code in my userlist class (businesslistbase)

IQueryable<TimeAndIssues.DalLinq.User> data = from d in ctx.DataContext.Users

select d;

foreach (TimeAndIssues.DalLinq.User d in data)

{

this.Add(User.GetUser(d.ID));

}

with

IQueryable<TimeAndIssues.DalLinq.User> data = from d in ctx.DataContext.Users

select d;

foreach (TimeAndIssues.DalLinq.User d in data)

{

this.Add(new User(d.ID, d.UserPassword, d.UserName, d.FirstName, d.LastName, d.Email, d.IsLocked, d.ModTS, d.ModUserID));

}

I added a new constructor to the User class (businessbase)  to return a user object where I pass in all properties.

compiles and fills the list... eliminates multiple fetches to the database..

thoughts?

 

 

 

sergeyb replied on Tuesday, July 15, 2008

Would it be better to simply have this.Add(User.GetUser(d)); ?

 

 

Sergey Barskiy

Senior Consultant

office: 678.405.0687 | mobile: 404.388.1899

Magenic ®

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: dmeadowcroft [mailto:cslanet@lhotka.net]
Sent: Tuesday, July 15, 2008 4:56 PM
To: Sergey Barskiy
Subject: [CSLA .NET] fetching with linq

 

I have a few months of working with .net, csla and c# but making great progress. looking for anyone to address some new code an tell me if there is any possible negatives to this approach.. thanks in advance..

I replace the following code in my userlist class (businesslistbase)

IQueryable<TimeAndIssues.DalLinq.User> data = from d in ctx.DataContext.Users

select d;

foreach (TimeAndIssues.DalLinq.User d in data)

{

this.Add(User.GetUser(d.ID));

}

with

IQueryable<TimeAndIssues.DalLinq.User> data = from d in ctx.DataContext.Users

select d;

foreach (TimeAndIssues.DalLinq.User d in data)

{

this.Add(new User(d.ID, d.UserPassword, d.UserName, d.FirstName, d.LastName, d.Email, d.IsLocked, d.ModTS, d.ModUserID));

}

I added a new constructor to the User class (businessbase)  to return a user object where I pass in all properties.

compiles and fills the list... eliminates multiple fetches to the database..

thoughts?

 

 

 



dmeadowcroft replied on Wednesday, July 16, 2008

 

I rewrote my constructor as this. eliminates need to setup paramaters

internal User(.DalLinq.User d)

{

LoadProperty<Guid>(IDProperty, d.ID);

LoadProperty<string>(UserNameProperty, d.UserName);

LoadProperty<string>(UserPasswordProperty, d.UserPassword);

LoadProperty<string>(FirstNameProperty, d.FirstName);

LoadProperty<string>(LastNameProperty, d.LastName);

LoadProperty<string>(EmailProperty, d.Email);

LoadProperty<bool>(IsLockedProperty, d.IsLocked);

LoadProperty<Guid>(ModUserIDProperty, d.ModUserID);

LoadProperty<SmartDate>(ModTSProperty, d.ModTS);

}

then  I can call it as

new user(d);

this seems to work fine.

doing a User.GetUser(d) as suggested above give compiler errors.

public static User GetUser(TimeAndIssues.DalLinq.User d)

{

User u = new User();

u.ID = d.ID;

u.UserName = d.UserName;

u.UserPassword = d.UserPassword;

u.FirstName = d.FirstName;

u.LastName = d.LastName;

u.Email = d.Email;

u.IsLocked = d.IsLocked;

u.ModUserID = d.ModUserID;

u.ModTS = d.ModTS;

return u;

}

gives compiler errors in windows forms whre I am calling User.getUser(ID);

 

Copyright (c) Marimer LLC