简体   繁体   中英

Reverse seeding (Getting info from database into a seeder) in C#

New user so I hope I can tell you what I want ---

I have a information in my database. I need to get that information in a seeder class in C#. I would rather not have to re-type the whole thing one line at a time.

Is there any way for me to do this? I am using Visual Studio 2012 and Microsoft SQL Server Management Studio if that makes any difference!

For example, I have CategoryId, Category as my table headers and the table is populated with autogenerated ID's but I have put in lots of categories.

PLEASE remember I am a new user so break down your answers with lots of examples PLEASE!!!

Thank you!

Your question is rather vague.

If your general problem can be re-stated as "How can I easily turns rows of data in my database into objects in C# with as little code as possible?", then I would recommend learning how to use an ORM layer. I use NHibernate to great effect. It provides a way of mapping tables in a database to classes in C# and does a ton of CRUD (CReate/Update/Delete) work for you. The alternative is to do the grunt work of writing stored procedures, pulling values out of a data set and constructing objects yourself; all of which is very tedious without an ORM layer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM