1

There are a lot of Sql table -> C# class methodologies, but I'm looking for the reverse.

Hypothetical situation:

I have N classes populated by some web service I consume, manipulate, then preform an action on. Now the boss wants said web service data persisted in a database.

I already have the classes defined, how can I quickly and easily (aka, lazily) generate a sql table off of each class?

2
  • Possible duplicate: stackoverflow.com/questions/47239/… Commented Oct 5, 2011 at 19:53
  • Easier said than done. How would you store STRING data in the database? VARCHAR(<size>) -How do you know the size to use. NVARCHAR() - Does the string need Unicode characers. CHAR()? Should booleans be stored as TinyInt. Should Private members be stored? What about GET/SET properties that convert a data type such as a flag into a literal value. But, it would be a handy tool Commented Oct 5, 2011 at 19:54

3 Answers 3

3

Entity Framework and nHibernate both allow you to use them in "code-first" mode, which involves writing classes then generating databases.

There is a walk-through of this on ScottGu's blog here: http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx

Sign up to request clarification or add additional context in comments.

Comments

1

you can use MS Entity Framework Code First approach:

Code First allows you to define your model using C# or VB.Net classes, optionally additional configuration can be performed using attributes on your classes and properties or by using a Fluent API. Your model can be used to generate a database schema or to map to an existing database.

read more about it here: EF 4.1 Code First Walkthrough

Comments

0

Entity framework 4 has a code first development feature, I haven't used it so can't really recommend it

ScottGu blog

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.