.Net 初学者应该费心使用 ORM 还是等到他获得更多经验?

发布于 2024-09-11 18:30:32 字数 505 浏览 5 评论 0 原文

我对 .Net 尤其是数据库方面还比较陌生。

我计划使用 .Net 和 C# 以及 Visual Studio 2008 重写一些遗留的 VB6 应用程序。

我研究了强类型数据集、表适配器等内容。 它工作得很好,但我发现强类型数据集不能完全管理,特别是当数据库模式发生变化并且代码感觉比面向对象更过程化时。 我发现它往往也会使代码变得混乱,并且生成的类型名称往往很长...

考虑到我对 .Net 相对缺乏经验,我真的不想进一步增加我的学习曲线,因为毕竟我有最后期限...... 我已经研究过 NHibernate 之类的东西,它看起来很吓人...我不确定是否有时间了解它们的 XML 文件等目前是如何工作的...

简而言之,我应该为 ORM 烦恼吗?等一下,我已经积累了更多使用 .Net 和 ADO.net 的经验……即使这意味着几个月后我安定下来时必须重写应用程序以使用 ORM。

我意识到这是一个主观问题,但我确信那些经历过两条路或必须培训新员工的经验丰富的开发人员的答案对我有用。

提前致谢,

I am relatively new to .Net and the database side of it in particular.

I'm planning to rewrite some legacy VB6 applications here using .Net and C# with Visual Studio 2008.

I've studied things like strongly typed datasets, Table Adapters, etc.
It works quite well but I find strongly typed datasets to not be perfectly manageable, especially when database schemas change and the code feels way more procedural than object-oriented.
I find that it tends to clutter the code a lot as well and the generated type names tend to be very long...

Considering that I'm relatively inexperienced with .Net, I do not really want to increase my learning curve even more, since after all, I have deadlines...
I've looked at things like NHibernate and it looks intimidating... I'm not sure to have the time to understand how their XML files, etc, work at the moment...

In short, should I bother with ORM at the moment or wait that I have built more experience with .Net, and ADO.net... even if it means having to rewrite the application to use ORM in a few months when I'll be settled.

I realize it is a subjective question, but I'm sure the answer of experienced developers who traveled both roads or had to train new recruits would be useful to me.

Thanks in advance,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

心的憧憬 2024-09-18 18:30:32

你可以尝试 BLToolkit:它是一个非常简单的 ORM:

public abstract class PersonAccessor : DataAccessor
{
    [SqlText(@"SELECT * FROM Person WHERE FirstName = @firstName")]
    public abstract List<Person> GetPersonListByFirstName(string @firstName);

    [SprocName("sp_GetPersonListByLastName")]
    public abstract List<Person> GetPersonListByLastName(string @lastName);
}

You can try BLToolkit: it's, among other things, a pretty simple ORM:

public abstract class PersonAccessor : DataAccessor
{
    [SqlText(@"SELECT * FROM Person WHERE FirstName = @firstName")]
    public abstract List<Person> GetPersonListByFirstName(string @firstName);

    [SprocName("sp_GetPersonListByLastName")]
    public abstract List<Person> GetPersonListByLastName(string @lastName);
}
几度春秋 2024-09-18 18:30:32

我强烈建议您研究 Mindscape 的 LIGHTSPEED。优秀的平台并建立在非常好的设计原理之上,一旦您掌握了基础知识,就会真正减少开发时间。还与 nhibernate、实体框架等进行功能比较。

I would highly recommend looking into Mindscape's LIGHTSPEED. Excellent platform and built on really good disign principals, really cuts down on development time once you get a hang of the basics. Also do a feature comparison to nhibernate, entity framework etc.

旧竹 2024-09-18 18:30:32

听起来您有许多(我猜相对较小的)应用程序需要重写,所以我很想不立即使用 ORM。对于您的第一个应用程序,只需尝试使用 ADO 自己编写数据访问代码 - 但请尝试确保所有内容都良好分离,例如使用 存储库模式。这样,如果您决定,您可以相当轻松地将 ADO DAL 替换为使用 ORM 的东西。

一旦您自己完成了这件事,您就会更好地了解 ORM 可以为您做什么以及您是否想要使用它(您可能会使用它!)。

另外,这实际上取决于您正在编写的应用程序类型,但我建议首先对模型进行排序(应用程序的核心类,通常是“员工”、“订单”等),然后使您的基于此的数据访问。通过这种方式,您可以使用 EF4、NHibernate 等,它们可以根据您的 .Net 模型类生成数据库架构。 (尽管这意味着您无法轻松使用 Linq to SQL,因为这需要首先准备好数据库)。

如果您确实想使用 ORM,并且正在使用 SQL Server,Linq SQL 很容易上手。主要缺点是您无法进行模型优先开发,它仅支持 SQL Server,并且它不再处于积极开发状态,因此可能不适合花时间学习。

It sounds like you have a number of (I would guess relatively small) apps to rewrite, so I'd be tempted not to use an ORM right off the bat. For your first app, just try writing the data access code yourself using ADO - but try and make sure everything is well-separated, for example by using the Repository pattern. This way, if you decide to, you could swap out your ADO DAL for something using an ORM fairly easily.

Once you've done it yourself, you'll have a better understanding of what an ORM can do for you and whether you want to use one or not (which you probably will!).

Also, and this really depends what type of app you're writing, but I'd suggest sorting the Model out first (the core classes of your app, commonly 'Employee', 'Order' and so on), and then make your data access based on that. Doing it this way, you could use something like EF4, NHibernate and so on, which can generate the database schema based on your .Net model classes. (Although it would mean you can't use Linq to SQL as easily, as that requires having the database in place first).

If you did want to use an ORM, and you're using SQL Server, Linq to SQL is easy to get going with. The main downsides are you can't do model-first development, it only supports SQL Server, and it's no longer in active development so might no be a good thing to spend learning time on.

寻找一个思念的角度 2024-09-18 18:30:32

您将必须学习一些数据访问方法,因此您也可以使用/学习 ORM。

我会选择微软的实体框架。

查看 WCF 数据服务: http://msdn.microsoft.com/ en-us/data/bb931106.aspx

You are going to have to learn some data access method, so you may as well use/learn an ORM.

I would go with Microsofts Entity Framework.

Have a look at WCF Data Services: http://msdn.microsoft.com/en-us/data/bb931106.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文