Click here to Skip to main content
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 4: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></instructor></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 OriginalGriff 381
1 Praneet Nadkar 237
2 Marcin Kozub 225
3 Sergey Alexandrovich Kryukov 200
4 Shweta N Mishra 161
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,327
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,920


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 21 Apr 2014
Copyright © CodeProject, 1999-2014
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