简体   繁体   English

在C#中反向播种(将信息从数据库获取到播种器中)

[英]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#. 我需要在C#的seeder类中获取该信息。 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! 如果有任何区别,我正在使用Visual Studio 2012和Microsoft SQL Server Management Studio!

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. 例如,我有CategoryId,Category作为表标题,并且该表中填充了自动生成的ID,但是我放入了很多类别。

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. 如果您的一般问题可以重新表述为“如何用尽可能少的代码轻松地将数据库中的数据行转换为C#中的对象?”,那么我建议您学习如何使用ORM层。 I use NHibernate to great effect. 我使用NHibernate效果很好。 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. 它提供了一种将数据库中的表映射到C#中的类的方法,并且为您完成了大量的CRUD(CReate / Update / Delete)。 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. 没有ORM层,所有这些都很繁琐。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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