Click here to Skip to main content
11,721,385 members (84,536 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Architect MVC , +
Hi Everybody,

My Database is in SQL Server and it is already working fine with Asp.Net site by using Connection String ( SQL Client ) but i want to implement it to an architectured way and multipurpose way.
So I have some question Regarding That.

Should i need to Use Entity Framework on Project??
Should I need to Use Entity Framework in WCF web service then access web service in Project??

Pls suggest me how to use database with the project.
Posted 12-Mar-13 3:14am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If you are trying to build a database independent library, the Enterprise Library Data Access Application[^] could help you.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Yes, You can use entity framework. all of you database operation you can use separate Project (Data Access Layer) in the application.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

If I'm correct from your question I understood that u might be using ADO.NET directly for connecting to database

if u are using ADO.Net

public IEnumerable<instructor> GetInstructorsADONET()
{
    var connString = ConfigurationManager.ConnectionStrings["SchoolContext"].ConnectionString;
    List<instructor> instructors = new List<instructor>();
    using (var conn = new SqlConnection(connString))
    {
        conn.Open();
 
        var cmd = new SqlCommand("SELECT Person.PersonID, Person.LastName, Person.FirstName, Course.Title, Course.Credits " +
            "FROM Course INNER JOIN " +
                  "CourseInstructor ON Course.CourseID = CourseInstructor.CourseID RIGHT OUTER JOIN " +
                  "Person ON CourseInstructor.PersonID = Person.PersonID " +
                  "WHERE (Person.Discriminator = 'Instructor') " +
                  "ORDER BY Person.PersonID", conn);
        var reader = cmd.ExecuteReader();
 
        int currentPersonID = 0;
        Instructor currentInstructor = null;
        while (reader.Read())
        {
            var personID = Convert.ToInt32(reader["PersonID"]);
            if (personID != currentPersonID)
            {
                currentPersonID = personID;
                if (currentInstructor != null)
                {
                    instructors.Add(currentInstructor);
                }
                currentInstructor = new Instructor();
                currentInstructor.LastName = reader["LastName"].ToString();
                currentInstructor.FirstMidName = reader["FirstName"].ToString();
            }
            if (reader["Title"] != DBNull.Value)
            {
                var course = new Course();
                course.Title = reader["Title"].ToString();
                course.Credits = Convert.ToInt32(reader["Credits"]);
                currentInstructor.Courses.Add(course);
            }
        }
        if (currentInstructor != null)
        {
            instructors.Add(currentInstructor);
        }
 
        reader.Close();
        cmd.Dispose();
    }
    return instructors;
}</instructor>


To avoid more code to be written and tested you can use ORM(object Relational Mapping)

public IEnumerable<Instructor> GetInstructors()
{
    List<Instructor> instructors;
    using (var db = new SchoolContext())
    {
        instructors = db.Instructors.Include("Courses").ToList();
    }
    return instructors;
}


Its not compulsory to use Entity framework depending upon your application and for any plans to migrate the data.


Refer this links

http://msdn.microsoft.com/en-us/library/ms178359(v=vs.110).aspx#orm[^]

http://msdn.microsoft.com/en-us/library/jj653752(v=vs.110).aspx[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 510
1 OriginalGriff 249
2 Mika Wendelius 170
3 F-ES Sitecore 80
4 cyycoish 70
0 Sergey Alexandrovich Kryukov 2,209
1 OriginalGriff 969
2 F-ES Sitecore 660
3 Maciej Los 609
4 Richard MacCutchan 560


Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 21 Apr 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100