How to properly separate database operations from gui / logic in C # when working with data sources?

It is very difficult for me to figure out how to specify a good search query for my problem: separating the interaction of gui and database in visual studio 2008 using Linq to sql.

According to my teacher in the C # im class, this is not correct if you allow the GUI to be dependent on a particular way of getting data.

As my project is currently set up, we have a mssql database where everything is stored. The solution is divided into 4 separate projects. UserGUI, AdminGUI, Logic and Db.

Now, using linq to populate lists and things like that, I use something like:

From the window form in the UserGUI project:

//The activeReservationBindingSource has Db.ActiveReservation as it value private void refreshReservation() { activeReservationBindingSource.DataSource = logic.getActiveReservationsQry(); } 

To the Logic project:

 public IQueryable getActiveReservationsQry() { return dbOperations.getActiveReservationsQry(this.currentMemberId); } 

To the database project:

 public IQueryable getActiveReservationsQry(int memberId) { var qry = from active in db.ActiveReservations where active.memberId == memberId orderby active.reservationId select active; return qry; } 

This makes sense to me, since I can send elements from lists completely to the database project and there it is easy to update / insert things into the mssql database. The problem is that it would be rather difficult to combine from the mssql database to tell the access version.

What should I read to understand how to do it right? Is creating my own classes the same values ​​as for Visual Studio for me when I create a dbml file? Should I then fill in, for example, a List in a logical project, which I turn into a GUI? For me, these are stitches, like "double work", but maybe this is the right way?

Be sure that we don’t read anything about design patterns or business logic, which seem to be a pretty big topic, and they look forward to further study outside the course.

I also thought that IQueryable inherits from IEnumerable and maybe that was the way to go, but I was not able to find any information that would make sense to me how to do this.

The GUI also knows about data sources, which, in my opinion, are bad, but cannot figure out how to get rid of.

Please understand that I tried to understand this with my teacher for half an hour today at the only tutoring available for this project, and then spent most of the day searching for similar answers on google, SO and classmates without any result.

+4
source share
5 answers

One key word to read: Model-View-Controller. These are the ideas you are after. Your View is a graphical interface. The “model” is the data layer, and the Controller is the code that takes data from the database and passes it to the graphical interface (and vice versa).

0
source

There is a post here on which I answered where the question was a bit like yours. I think it's worth a look.

Hi

+2
source

Check out the repository template. There are several implementations you can find in googling "Linq repository".

you can watch the MVC Storefront series here: http://www.asp.net/learn/mvc-videos/#MVCStorefrontStarterKit . In this series, Rob Conery creates the Linq IQueryable repository, which returns custom-created objects instead of linq objects.

0
source

Perhaps you can take a look at Data Summary

0
source

According to my teacher in the C # im class, this is not correct if you allow the GUI to be dependent on a particular way of getting data.

Honestly, your teacher is an idiot. This is one of the stupidest statements in terms of the database I have ever read. Of course, you want to be dependent on the particular method of retrieving data if this is the most efficient way to retrieve data (which almost always depends on the database and means not to use LINQ to SQL for complex queries, but that's another question). Users care about performance, not database independence.

Very few real applications really need to be database independent. Yes, there are some types of commercial software for mailboxes (although I think this is usually a mistake, and one reason why every commercial product I have ever used is poorly designed and terribly slow).

And since each database implements SQl differntly, even using ANSII sql is not completely database independent. Access, in particular, is not where it is close to the ANSII standard. It is impossible to write code that will work correctly in every possible database.

-one
source

All Articles