我应该使用实体框架还是直接使用SQL查询来获取WPF中的数据? [英] Should I use entity framework or just direct SQL queries to get my data in WPF?

查看:72
本文介绍了我应该使用实体框架还是直接使用SQL查询来获取WPF中的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Winforms转移到WPF,我的搜索问题上的谷歌搜索仍然让我感到疑惑。



我应该使用



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);





当我需要从SQL获取数据或我是否应该使用实体框架?





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;
}





我开始使用Entity Framework构建我的应用程序,因为它感觉类似于拥有一个DataSet我以前习惯但我有点想在继续之前得到一个真正的答案。



我已经习惯了来自Winforms的TableAdaptors和BindingSources,有点不确定为什么WPF不使用相同的方法。



我尝试过:



我试过谷歌,寻找在WPF中连接SQL的最佳方法。



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.

推荐答案

这个问题没有真正的答案。这是个人喜好的问题。



至于TableAdapters,那些是训练轮。如果你不想要,你根本不需要使用它们。



还有很多其他方法可以从数据库中获取你想要的数据,比如直接SQL查询使用您在第一个示例中的代码,实体框架,NHibernate,存储过程,...



这取决于您想要的代码类型写作和你想要处理的乏味程度。
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.


这个问题没有答案,这完全是一个意见问题。



实体框架将允许开发时间的潜在增加。

使用ADO&数据集将允许开发人员在功能知识和性能提升方面的潜在增长。
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.


这篇关于我应该使用实体框架还是直接使用SQL查询来获取WPF中的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆