views:

52

answers:

3

In a project, one of my entities is House which has many enumeration properties (for example housetype). Using .NET, Linq to Sql and Sql Server how can I create a db with enumeration and use it with Linq to Sql? What should be my approach?

A: 

Either you create a standalone table for enum or you just store this housetype as int and in .net you create enum and then cast it to int or visa verse

Andrey
ok but I want Linq to Sql does the cast.
erasmus
+1  A: 

In our L2S application, all our tables which act as an enumeration table have 'enum' appended at the end of the table name (e.g., HouseTypeEnum). We do not create application entities for these tables. In our C# code, we have class enumerations whose values match what is in the database. The class name matches the DB table name, for clarity.

Randy Minder
+2  A: 

If you just mean mapping a something like a HouseType property to a column on the House table. Then LINQ to SQL will do it for you.

See this article for an example.

This article shows how to use an enum as a discriminator column. Not related to the question, but very handy.

Mike Two