Showing posts with label Entity Framework. Show all posts
Showing posts with label Entity Framework. Show all posts

Friday, August 21, 2020

Creating Entity Relationship Diagrams

Here is what I did to create an Entity Relationship diagram for a project at work.

Prepare for the solution at this Stack Overflow article

Download SQL Server Data Tools (SSDT) for Visual Studio

Modify Visual Studio by adding or removing workloads and components

Follow the steps listed in the answer at the SO article. 

- Open Visual Studio

- Create a project or open an existing project (must be Visual Basic, Visual C# project, or Console Application)

- Right-click the project and choose Add -> New Item…

- Under Visual C# Items select “Data”

- Select the template “ADO.NET Entity Data Model”

- Give it a name and click “Add”

- Select “Generate from database” or “Empty model”

- If “Generate from database” selected enter connection info, choose the database objects and done!

The model is stored as a “.edmx” file. 

- In the visual representation of the edmx file in Visual Studio, arrange the entities so that the relationships are easy to follow.

- Right click in the edmx file and choose Diagram -> Export as image. Save the image. 

Wednesday, April 27, 2011

Reducing Sleeping Dragons

A few weeks ago I added a column to a SQL table DateCreated.  I wanted to track when the records were getting created.  I provided a value for the existing columns and then made it not nullable and provided getdate() as its default.  I have done this quite often in the past and in the other frameworks I was in it never was a problem.

This time it was.  I had made other changes to the database the project used.  I updated the edmx file for the data access layer so it would refresh my object model for my code.  I did not pay close enough attention to the fact that it now added code to account for the new DateCreated column.

Yesterday we got an error.  When looking at the SQL trace I saw that Entity Framework was passing in a '0001-01-01 00:00:00' for the date value because the code giving the values was not providing it a value.  I was counting on the app (including the data layer) to not provide a value.  The database definition would provide getdate().

Entity Framework did only half the job that needed doing.  The presentation layer, or service layer or business layer should have been updated to provide a value if the data layer gets updated with the DateCreated column.


I am glad that we are getting away from using ORM solutions.  We are instead relying on lightweight utilities to create a data layer using only ADO.NET.  My colleague, Sam started this with LOEF.  He is now developing NOEF (No Entity Framwork perhaps with a better name).  This will reduce the sleeping dragons we have to deal with.