EF4可以为我生成POCO,还是自己写? [英] Can EF4 generate POCO for me, or do I have to write them myself?
问题描述
问题是我在互联网上遇到的每个教程都会手工生成他们的课程。我的意思是,他们都说现在我要用一个叫做Orders的新类,具有以下属性,然后继续写出来。如果我开始一个新的项目,那可能是正常的,但是我正在移植我的旧网站,所以我的数据库中有20个表。如果我手头写出所有这些,我会一整天都在那里:D
加我不知道如果我做了一些事情会发生什么数据库的更改(因为我将不得不回头再手动更新我的所有课程)。
我希望EF4有类似于类图的东西,在那里我可以将其指向我的数据库,并根据它为我生成一堆类。
我有点迷失了。我正在这样做吗?
你应该看看 ADO.NET C#POCO实体生成器。因此,您应该能够从现有数据库生成模型,T4模板将根据您的数据库表等生成您的POCO类。
这里是一个链接MSDN解释了如何使用更新模型向导从数据库更新模型。
I've been playing about with the Entity 4 framework lately and it's pretty nifty. I've setup a class called Customer.cs with some properties like Name, Address etc. I also have a class called StoreEntities.cs which binds these back to the database through DbSet. It works fine and I can pull all my customers from the database.
The problem is every tutorial I come across on the internet generates their classes by hand. What I mean is, they all say something like "Now I'm going to make a new class called Orders with the following properties" and then proceed to write it out. That might be ok if I was starting a new project, but I'm porting over my old website so I have upwards of 20 tables in my database. If I go through and write all these out by hand I'm going to be there all week :D
Plus I'm not sure what would happen if I made some changes to the database (since I would have to go back through and update all my classes by hand).
I was hoping EF4 would have something similar to a Class Diagram, where I can point it at my database and have it generate a bunch of classes for me based on that.
I'm a little lost on this. Am I going about this the right way?
You should take a look at the ADO.NET C# POCO Entity Generator. With that you should be able to generate your model from your existing database and T4 templates will generate your POCO classes based on your databases tables, etc.
Here is a link to MSDN that explains how to Update Model from Database using the Update Model Wizard.
这篇关于EF4可以为我生成POCO,还是自己写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!