Skip to content

Entity Framework visual design surface and code-first code generation for EF6, Core and beyond

License

Notifications You must be signed in to change notification settings

msawczyn/EFDesigner2022

Repository files navigation

Entity Framework Designer - VS2022 Edition

Entity Framework visual design surface and code-first code generation for EF6, EFCore and beyond.

For Visual Studio 2022

Model and generate code for both Entity Framework v6.x and Entity Framework Core 2 through 8.

Install with NuGet from the Visual Studio Marketplace

Complete documentation in the project's documentation site

This Visual Studio 2022 extension is the easiest way to add a consistently correct Entity Framework (EF6 or EFCore) model to your project.

It's an opinionated code generator, adding a new file type (.efmodel) that allows for fast, easy and, most importantly, visual design of persistent classes. Inheritance, unidirectional and bidirectional associations are all supported. Enumerations are also included in the visual model, as is the ability to add text blocks to explain potentially arcane parts of your design.

While giving you complete control over how the code is generated you'll be able to create, out of the box, sophisticated, consistent and correct Entity Framework code that can be regenerated when your model changes. And, since the code is written using partial classes, any additions you make to your generated code are retained across subsequent generations. The designer doesn't need to be present to use the code that's generated - it generates standard C#, using the code-first, fluent API - so the tool doesn't become a dependency to your project.

If you are used to the EF visual modeling that comes with Visual Studio, you'll be pretty much at home. The goal was to duplicate at least those features and, in addition, add all the little things that should have been there. Things like:

  • importing entities from C# source, or existing DbContext definitions (including their entities) from compiled EF6 or EFCore assemblies
  • multiple views of your model to highlight important aspects of your design
  • the ability to show and hide parts of the model
  • easy customization of generated output by editing or even replacing the T4 templates
  • entities by default generated as partial classes so the generated code can be easily extended
  • class and enumeration nodes that can be colored to visually group the model
  • different concerns being generated into different subdirectories (entities, enums, dbcontext)
  • string length, index flags, required attributes and other properties being available in the designer

and many other nice-to-have bits.

Code generation is completely customizable via T4 templates. The tool installs templates that target both EF6 and EFCore, and generate both a code-first DbContext class and POCO entity classes. The DbContext code is written to allow consumption in ASP.Net Core in addition to any other project type, so you'll have flexibility in your development.

Note: This tool does not reverse engineer from the database (i.e., "database-first"). There are other, quite well-maintained open-sourced projects that provide that functionality. Once you've created an assembly from a reverse-engineered database, you can drop it onto an empty design surface and create a model from that, then evolve your code using that model.

You can read more about how to use the designer in the Documentation site.

Migrating from VS2019 You'll have to change a line in your model's .tt file to accommodate how Visual Studio 2022 handles library imports in text templates.

Change line 5, which reads

#><#@ assembly name="EnvDTE"

to be

#><#@ assembly name="Microsoft.VisualStudio.Interop"

That's it. Of course, if you customized any of the standard templates, you'll have to go through the customizations the same way you've always done and bump your changes up against the new templates. Not much has changed that didn't absolutely need to be changed due to the VS2022 differences, but there may be a bugfix or two your customized templates don't have. But, hey ... if you've been customizing the templates, you know the drill, right?

Shout out and a big thanks

to for providing free development tools to support this project.

We're looking for help!

Let's be honest -- the documentation is woefully out of date. There are a ton of new features in the tool that aren't mentioned in the docs anywhere, and that's just plain not good.

If you're interested in helping out, please drop a note at the GitHub project site. More hands make the work lighter, and I know there are some really bright people amongst the userbase who are much better at writing documentation than I am.

Change Log

4.2.8

  • Better handling of N-N relations in assembly parser
  • Better detection of principal/dependent roles in assembly parser
  • Removed "dbo" as default schema in design surface properties. Not specifying will allow the database to use whatever default schema is appropriate for it.
  • Corrected some deficits in how column name overrides were being handled in EFCore

4.2.7

  • Support for per-entity inheritance in EF7
  • Added option to generate nullable indicators
  • Added temporal table support for EFCore6 and above. These aren't supported by every database, and you're on your own to know if your database supports them.
  • Arrays of native types can now be used as property types in EFCore8+ projects
  • Aggregate ("owned") types can now be stored as JSON properties in EFCore7+ projects
  • Associations with transient, non-collection objects can be stored as JSON properties in EFCore7+ projects
  • Added support for reverse engineering EFCore v8 assemblies
  • Fixes issue when generating code for properties that have a default enumeration value. Thanks to @equipatuequipo for the pull request.
  • Association classes are back, but only for cases where each side of the many-to-many bidirectional association has a single identity property.
  • Removed EFCore2 and EFCore3 parsers. Those EFCore versions have been obsolete for quite a while. If you need to use them, you can still use the 4.2.5 version of the extension.
  • Constructors with required-but-transient associations no longer have those associations as parameters. If that constructor is needed, add it to the partial class file.
  • Tightened up the concept of transient entities. We're now generating better code for these and the restriction that transient associations must be auto properties has been removed.
  • Entities now update their displays immediately when the Persistent flag is changed.

4.2.5

  • Adds missing XML documentation for public and protected members
  • Fixes "No 'Is Identity' setting when adding a new entity property (version 4.2.44)" (see #63)
  • Fixes "Bad intersection table generation when M:M tables have the same primary key name" (see #64)
  • Fixes "Table names are pluralized even when flag set to false" (see #65)

4.2.4

  • Reduced model load time by 98%
  • Exposed "Collapse Selected Elements" context menu choice for diagrams
  • Fixed colors in saved diagram images (see #62)

4.2.3

  • Added HierarchyId as a property type
  • Added optional index name for indexed properties
  • Added properties to bidirectional associations allowing custom naming of FK columns in join table
  • New example code for EF6 and EFCore. Thanks to David V for the pull request.
  • Class, property, enum and enum value names are now escaped if they match a reserved C# keyword
  • Ensured that a foreign key property's IsForeignKeyFor value is reset when the association is removed and that property is an Id property. (see #47)
  • Replaced legacy EF6Designer.ttinclude and EFCoreDesigner.ttinclude files for legacy model file backward compatability. (see #45)
  • Assembly import is a bit smarter now in detecting and using indexes and views
  • New glyphs in diagram and explorer to show transient and view entities
  • Fix bad constructor generation when multiple associations exist between the same classes (see #50)
  • Removed modeling restriction on unidirectional many-to-many properties in EFCore7+ projects (see #54)
  • Updated file sync logic for generated files. Thanks to Sancho-Lee for the pull request. (see #57)
  • Fix bad code re: key fields in derived types. (see #55)

4.2.1

  • Added support for EFCore7
  • Added ability to import EFCore7 assemblies
  • Added ability to use property types not available in the select list, along with a global option enabling this feature in Tools/Options/Entity Framework Visual Editor (see #28)
  • Added support for DateOnly and TimeOnly types in EFCore 6+
  • Added ability to specify decimal precision in EFCore5+ projects
  • Fix for View->Other Windows->Entity Model Explorer not working (see #29)
  • Fix error in code generation template for EFCore5+ projects

4.2.0

  • Added ability to import EFCore6 assemblies
  • Added database default values to properties (see #15)
  • Extension now obeys Visual Studio theme colors (see #9)
  • Added Persistent property to ModelClass to generate [NotMapped] when false. (see #17)
  • Entity constructors with required navigation properties are now generated with either the required navigation target or its foreign key property, if available (see #21)
  • Fixed other Entity Framework assembly imports that broke with VS2022 moving to 64-bit (see #14)
  • Fixed problem with generated Timestamp concurrency check (see #20)

4.1.2

  • Added ability to create association classes via drag and drop of an entity onto a bidirectional many-to-many association
  • Restored ability to open secondary diagrams
  • Compiler update to Visual Studio v17.1.0 fixes missing designer menu items

4.0.1

  • Added validations preventing use of temporal tables in unsupported scenarios

4.0.0

  • VS2022 extension
  • Added support for EFCore6
  • Added support for temporal tables

Earlier changes at the VS2019 version.

About

Entity Framework visual design surface and code-first code generation for EF6, Core and beyond

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published