c# - oop asp.net classes for sql server queries -


In SQL Server, I have students and department tables I want to get student records from student tables; With the departments of their department data (so I joined them) and show them in an asp.net page

In ASP.NET I have ASP.N. Code CodeHighand has created a studio class type to use in the list. The list, like this, takes the type of student class data:

  list & lt; Students & gt; Lst = new list & lt; Students & gt; ();  

But let me meet the student with their department datas. . Therefore, I created a custom category in the asp.net side called StudentsandDepartments

Now the list takes this class:

  from the list & lt ; StudentsAndDepartments & gt; Lst = new list & lt; Students and Deptrtments & gt; ();  

My question; Do I need to create a new custom class for every query? If I create a custom class to use every query, then there are too many classes inside the solution. I think I am doing wrong .. What should I do? Thank you for helping ..

You do not create the "Students and Dependents" class.

What you are doing here, trying to "level" the domain model, and the use of a class can be better defined as such a relationship.

You create and associate your domain model.

  Public class student {public string lastime / * The above student has a 'scalar' property. You will have other names such as FirstName, Student Identification Number, etc. * / / * Below is the 'Relationship' property, use one of the two below, but * / Public Icicle & lt; Department & gt; Departments; Parents department of / * or * / Public Department; } Public Sector Division {Public String Division Name Public Iislogo & lt; Students & gt; Students; }  

Then you "Hydrate" Domain Model.

Now this is where things can actually be different.

This is the unit framework with POCO.

ADO Net can do this. You write "SerialIsers" which convert the idetider to your object model. This manual mapping with ADO.NET, you can write different stored procedures ...

  dbo.uspStudentsGetAllWithParentDepartments dbo.uspDepartmentsGetAllSimple dbo.uspDepartmentsGetAllWithChildrenStudents  

Something similar

Now, where I usually retreat from other people.

I do not write junk SQL statements. I write 2 different SQL statements (in one stored procedures) to get your data.

  dbo.uspStudentsGetAllWithParentDepartments  

like the way

  select st.EmpKey, st.LastName, st .FirstName dbo.Student Saint is dept.DepartmentKey, dept.DepartmentName the dbo.Department department where exists (select zero dbo.Student innerStud where innerStud.ParentDepartmentKey =  

now entity framework can sql- writing to you, but it is a start-up cost if you ever have not seen it before.

My Microsoft-only friends do not show that capable of EF Does merge () functions like NHibernate (another ORM device) which is a deal breaker for me, but this is a deep discussion.

Define your domain-objects, their relationships , And then ask questions about "What is the best way to hydrate my domain model, based on my existing skill sets" (or without Skillet part if you are open to a new method)

Here's another answer for one Link's post ... which is serial code for ado.net like your object hydrating.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -