Hi, I suggest you re-design your code. This is like doing a MVC pattern which is similar to this thread:
http://groups.google.com/group/DotNetDevelopment/browse_thread/thread/a66af459fe761075/a64979afe70bbe41?lnk=gst&q=mvc%2Bbenjnunez#a64979afe70bbe41 You can do this if you want a "look-and-feel" of Java, but in C#. :) Cheers! Benj On Feb 13, 8:35 am, Adam <[email protected]> wrote: > Hi, > > I may have designed something fundamentally flawed.... > > I have three c# projects - a UI, the Business Logic (BL) and a Data > Access Layer (DAL) > > Some pseudo(ish) code to illustrate > > DAL is: > > class DAL > { > public interface IDALUser > { > string UserId { get; set; } > } > > public void SaveUser(IDALUser myUser) > { > /// Save the user using the properties > /// If UserId is an empty string then generate ID and INSERT > /// otherwise UPDATE > } > > public List<IDALUser> SearchForUser(IDALUser searchUser) > { > /// User properties to generate SQL SELECT statement > /// foreach row in results > /// Clone() the supplied object, set its properties from the > DataTable, add it to the return list > } > > } > > my Business logic (references DAL project) > > class User : IDALUser > { > public string UserId > { > /// get and set > } > > public void Save() > { > DAL.SaveUser(this as IDALUser); > } > > public List<User> User GetById(string userId) > { > List<User> returnList = new List<User>(); > searchUser = new User(); > searchUser.UserId = 1; > > foreach(IDALUser current in DAL.SearchForUser(this as IDALUser) > { > returnList.add(current as User); > } > > return returnList; > > } > > OK, this works. However.... > When some idiot (me) is implementing the UI using the BL, they are > able to set the UserId on the BL object. I would rather this property > were internal as it should only be set by the DAL (it tells me whether > to INSERT or UPDATE). Can I achieve this? Or is this approach just bad > design? > > If you got this far, thanks for your time. > Any comments/suggestions/abuse gratefully received > > Adam
