locked
need a little help with a project design RRS feed

  • Question

  • hi,

    i am not sure this is the right forum for my question, but i hope it is.

    i am going to design a software that many users are going to use simultaneously on difrrent computers obviously.

    the program need to comiunicate with an sql server so it can retrive and insert data from the db 

     

    my problem is how to load the data from the db, because i don't want to retrieve it per "form" i want to insert the data into a data structure at startup,

    but if i get the data at start up i cant see the changes done to it by another user...

     

    do you have any suggestions? 

    i hope my question was clear enough if not ill try to re ask it [=

     

    thanks in advandce

    jony [=

     

     

     

     

     

    Tuesday, August 16, 2011 5:35 AM

All replies

  • Jony,

    Is this going to be a web app or windows app?  Either way, I have to ask the question why you want each client to work in totally disconnected state with its own local data?  Is this due to a technical requirement or due to a perceived ease of programming requirement?

    Because from an ease of design perspective, Entity Framework will give you a nice data model to work with so you don't have to actually do the tedious ADO.NET tasks of querying the database directly to fill in each form.  Entity Framework can be designed to work in a disconnected mode which cuts down on a lot of the database traffic but it still will need to hit the database some as it persists changes to your objects and the state manager handles getting updated entities from the database (only if needed) using identity mapping.  There are a lot of ways to design an application using EF I would have to know more about your application to recommend the best one. 


    Tom Overton
    Tuesday, August 16, 2011 2:08 PM
  • hi,

    thanks for your response[=

     

    i am building a windows app i forgot to say, sorry

     

    i have a training organization with a lot of courses and trainees,

    and i am writing a program that spouse to mange all the people information with the information of the courses they participated on, and so on...

    each teacher/manager will have an instance of the program.

     

    so for me to work with the data i need to retrive it from the database to my own data structure for example a list of trainees(class) and so on and so on... 

    so for example if i am now showing a form with all the information of a trainee i don't want to connect to the database when the window opens do some sql's and that show the data i want to show it from my datastracture otherwise i lose a lot of the oop power...

     

    thanks again for the help! [=

    Wednesday, August 17, 2011 9:11 AM
  • The reason ORMs like EF exist is to make it easy to bridge that gap between the object orientated world of your programmes and the tables and relationships world of the database.

    So I also think you should take a long look at Entity Framework.

    Thursday, August 18, 2011 6:43 PM
  • Entity Framework is LINQ to SQL?
    Thursday, August 18, 2011 11:13 PM
  • No, Entity Framework isn't LINQ to SQL.  Entity Framework is a full featured ORM that can be used to model complex enterprise database structures into meaningful entities. LINQ to SQL is the old method of doing simple ORM in the .NET framework but has now been pretty much replaced by Entity Framework.  If you have a simple SQL Server database and only want to map some tables directly to entities then you can use LINQ to SQL but it would be best to use Entity Framework from this point on.    
    Tom Overton
    Friday, August 19, 2011 1:12 AM
  • hi, sorry for the long delay,

    i read about EF4 and it sound really cool unfortanatlly i am using the .net 3.5 framwork

    so i can't use the EF =\

     

    however this wast really my question, my question is more of a design question,

     

    the question is how to shear the information i guess,

    because i don't want to work with the data base at all except at the beginning , or at least as less as possible...

     

    any suggestions?

    Sunday, August 28, 2011 12:00 PM
  • Jony,

    You might be able to use Linq to SQL to do what you need to do. Basically what you will be doing is using a disconnected context, and when the client is ready to persist changes to the database, it will pass it back to the server and do optimistic concurrency checking on it before applying the update (meaning it will compare all original fields of the source to the current fields of the target table before doing an update to make sure no changes by another user were done that might be overwritten).  However, this mode is really meant for short disconnected periods of time like in an ASP.NET application dealing with a single request.

    If the client really needs to work for a long period of time disconnected from everything, with a full version of the whole database and be able to query and do updates and such, then you have no choice but to basically replicate the whole database on the client.  I haven't worked with Microsoft Access in a while but you might think about putting your data into Access and doing something with Jet replication.  I think it might be kind of flaky though.  You might also be able to use local copies of SQL Server Express although you would have to create routines to replicate the data back to the central database since the express version doesn't let you publish or distribute.

    If the clients can't have access to the database, will they have access to the internet?  In that case you would want to implement a service oriented approach like a silverlight application does (but you can use anything like winforms, wpf, etc) that doesn't open a connection to the database but just uses web services.  This might be your best bet.  Read up on RIA Services, ADO.NET Data Services, and WCF if you aren't familiar.   

     

     


    Tom Overton


    • Edited by Tom_Overton Sunday, August 28, 2011 1:28 PM added the bit about sql express
    Sunday, August 28, 2011 1:15 PM
  • thanks for the fast replay!

     

    i will read about wcf and see if this helps me,

     

    but anyway can you give me a glance of how it would have work using EF4?

    Sunday, August 28, 2011 1:51 PM
  • Actually EF4 might not have been the best approach because it still uses ADO.NET to connect to the database and needs to connect to the database regularly.  It can't create a totally stand-alone data model that runs on the client.  You would need a file sharing database like Access or a local copy of SQL Server to do that.

    But with WCF your client doesn't have to be concerned with gathering all the data it needs up front, the web services would be there for the client anytime it needs to retrieve data or do update requests.  

     


    Tom Overton

    Sunday, August 28, 2011 2:02 PM
  • I don't get why you must use .net 3.5.

    There's a free version of vs2010 and the dotnet frameworks don't interfere with one another.

    Why are you stuck with 3.5?

     

    So you want something to get a copy of data from the central database and then work totally disconnected?

    Consider sql ce4 on the client.  The database is just a file.

    Copy your data to the local database or copy the database to the machine.

    Do your stuff locally.

    If you don't want to write data back to anywhere then the sql ce file can just be xcopy'd or ftp'd onto your machines pre populated with data.

    If you wanted to write the data back via occcasional connection you could use ms sync.

     

    If you just want a quick and dirty way to connect up winforms or wpf to data then strongly typed datasets are worth considering.

    So long as you don't need any business rules validating or manipulation of data between the  database and presentation layer datasets would do the job.

     

    Bear in mind that EF4 can be used to generate classes.

    You could do that to generate the bare bones of you objects and then use them in another solution without using EF4.  That'd save you hand coding all the lists of fields.  Assuming you need classes and and not datasets. 

    Sunday, August 28, 2011 3:27 PM
  • Andy,

    Thanks for bringing up SQL ce4.  I agree if Jony could upgrade to .NET 4.0 and take advantage of SQL ce4 that would be a good option, better than SQL Express and Access.

    But it sounds like Jony needs the clients to see updates to the data from other users basically realtime, so maybe all those solutions aren't the best.  I think in that case a service oriented approach is going to be the best option.


    Tom Overton

    Sunday, August 28, 2011 4:04 PM
  • first of all, thanks for helping,

     

    to you'r question

    i cant work on .net 4.0 because i am working on a close network witch dosent have the 4.0 framework unfortunately,

     

    any way i think you guys got it a little bit wrong what my problem is,

    i am fine with the database acsses, linq to sql is good enough for what i need,

    i'm having problem with the bushiness logic of the design,

     

    i am trying to design the logic so that i load all of the data into class like trainees, courses etc..

    however if i do load all the data at start, if any one makes a change in a trinee for excemple non of the other users will see the change,

     

    i need something like a trainee manger class witch is a singleton witch is the same for all the users that will send references to trainees or copies of them to users so that every change will affect everyone.

     

    in web its easy to make since everyone can access the same singleton but in windows app i don't know how to do that...

     

    thanks again in advance

    jony

    Sunday, August 28, 2011 4:07 PM
  • Jony,

    What you just described is really what EF4 is all about, too bad you can't get them to upgrade to .NET 4.0!

    But in that case, what you really need is perhaps a repository pattern.  You will define of set of CRUD operations and query operations on objects that you know you will need to be doing on the client and create a class that implements this interface that talks to the database and retrieves or updates those classes.  Something like:

    public interface IMyDataRepository 
    { 
      List<Trainee> GetAllTrainees(); 
      List<Trainee> GetTraineeByName(string _last, string _first); 
      List<Course> GetAllCourses(); 
      UpdateTrainee(Trainee _trainee)();
      ...
    } 
    

    You really want to be creating this "on demand" interface instead of trying to load all your objects up front.  You don't want to get in the habit of loading everything up front into all your objects and their children objects.  This can create unneeded database calls and slow things down.  You want to implement lazy loading so you only load the classes and the class members in those classes that you need to use for any given request.


    Tom Overton
    Sunday, August 28, 2011 4:22 PM
  • Just a repository won't notify other users of changes.

     

    Sync framework could do, so long as you're not in a rush to be notified.

    If you need to be notified of other users changes as they happen then that's tricky.

    WCF polling duplex is the full on way to do it, if you have a lot of users.

    or

    Push changes to a central server via a windows service.

    Have this notify clients of changes via sockets or message queues.

     

    Occasional connection with updates which will not usually clash is probably best handled with sync.

    Sync your data to a local sql ce database from one central master one, do your linq stuff on the client and let sync worry about the tricky bits.

    Tuesday, August 30, 2011 2:38 PM
  • Andy, reading Jony's last post it looks like Jony is not really looking for a disconnected database architecture which would require syncing.  Jony is wanting a data model like EF4 can provide.  Unfortuatenly they are not able to use EF4, so another option is to just work with a repository which would be a standard front end, a sort of "date model", for the clients to talk to the central database.  They can use Linq to SQL on the back end as the DAL.  Or, they can try to use NHibernate but I can't give much direction there since I haven't used it before.   


    Tom Overton
    Tuesday, August 30, 2011 3:22 PM