1

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?

2
  • 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 you Commented Jan 5, 2015 at 1:49
  • Well... This is what I was afraid. In any case, thank you! Commented Jan 5, 2015 at 2:12

1 Answer 1

0

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.

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

2 Comments

Chris, tnx! Yes, I see what you are talking about. But, how I can get this information in c# code?
...I'd like to use this information in my app, but I don't want to hardcode it.

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.