Click here to Skip to main content
15,911,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am moving to WPF from Winforms and my google searches on my question have still left me wondering.

Should i just use

SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=myDB;Integrated Security=true;");
SqlDataAdapter adaptor = new SqlDataAdapter("SELECT ID,Name,Surname,JobTitle FROM tblEmployees;", con);
DataTable dt = new DataTable();
adaptor.Fill(dt);


When i need to get data from SQL or should i use Entity Framework?

public ObservableCollection<tblEmployee> GetEmployees()
{
    EmployeesEntities Context = new EmployeesEntities();
    Context.tblEmployees.Load();
    return Context.tblEmployees.Local;
}


I started building my App using Entity Framework as it felt similar to having a DataSet which is what i am used to but i kinda want to get a real answer before carrying on.

I am so used to TableAdaptors and BindingSources from Winforms and a little unsure as to why WPF doesn't use the same approach.

What I have tried:

I've tried Google, searching for the best way to connect to SQL in WPF.
Posted
Updated 18-May-18 8:04am

There is no "real answer" to this question. It's a matter of personal preference.

As for TableAdapters, those are training wheels. You don't really have to use them if you don't want.

There are plenty of other ways to get the data you want from the database, like direct SQL queries using the code you have in your first example, Entity Framework, NHibernate, stored procedures, ...

It just depends on what kind of code you want to write and the level of tediousness you want to deal with.
 
Share this answer
 
Comments
BeginnerCoderPete 18-May-18 15:51pm    
Thank you for your answer. I'm glad to hear it's about preference. I will just work with both until i decide which will be my preferred method. I do quite like Table Adapters but i guess since i started out with vb.net then i don't really know much different until now.
There is no answer to this question, it is all a matter of opinion.

Entity Framework will allow for potential increases in development time.
Using ADO & Datasets will allow the developer potential increases in functional knowledge and performance increases.
 
Share this answer
 
Comments
BeginnerCoderPete 18-May-18 15:52pm    
Thank you for your answer, i guess there will be pros and cons to both so i will have to just work out in time what method i prefer.
MadMyche 18-May-18 19:11pm    
Anything we write from scratch is ADO & DataTables

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900