I'd like to ask, is there any way to get column properties in c# code via entity framework mechanism (database first approach, EF v5)? For example, I have a table in DB, which has a column of type nvarchar(256) with NOT NULL option. Can I get such information using ObjectContext? Or the only way is make a query direct to DB?
-
I think this question / answer will have what you're looking for stackoverflow.com/questions/3815460/…, but short answer is looks like nothing out of the box for youPrescott– Prescott2015-01-05 01:49:27 +00:00Commented Jan 5, 2015 at 1:49
-
Well... This is what I was afraid. In any case, thank you!Core– Core2015-01-05 02:12:56 +00:00Commented Jan 5, 2015 at 2:12
Add a comment
|
1 Answer
If you have a db already set up, you can add a new edmx to your project (Visual c#>ADO.NET Entity Data Model). Choose EF Designer from database, set your connection string, and generate classes from the db context. Once the edmx is added you can select the edmx and see the model diagram. Select one of the models in the diagram, right click and click 'table mapping'.
To see if a property is nullable, expand myEdmx.edmx, myEdmx.tt and then open the generated class you want.