Giter Site home page Giter Site logo

msawczyn / efdesigner Goto Github PK

View Code? Open in Web Editor NEW
363.0 18.0 61.0 2.36 GB

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

License: MIT License

Batchfile 0.07% C# 94.42% Smalltalk 0.17% CSS 0.02% HTML 0.05% JavaScript 0.01% Rich Text Format 2.42% PowerShell 0.06% ASL 2.74% XSLT 0.05%
code-generation code-generator modeling visual-studio visualstudio entity-framework-core entityframework ef6 efcore entity-framework

efdesigner's People

Contributors

dcastenholz avatar dependabot[bot] avatar falthazar avatar kernelith avatar michael-sawczyn avatar michaelsawczyn-awh avatar msawczyn avatar opzet avatar ruialias avatar tdabek-euvic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

efdesigner's Issues

Integration w/ Owin or Asp Identity

I did read the excerpt detailing that this is not meant to import existing models, and that makes perfect sense.

But configuring asp.net and owin is a significant undertaking, so I'm curious as to an alternative to use with this system?

Perhaps an "interface" between the two, like a table with nothing but foreign keys for UserId, Group, Role, etc, as a layer on top of owin, with which my application-models designed in EFDesigner would interact?
I'd still have to customize the linkages manually in the code, so the model wouldn't perfectly reflect (visually speaking) what is actually taking place.. Adds a bit of overhead too. But maybe that's the answer?

Just curious if anyone has stepped through similar and has any suggestions. Thank you!

Output directories cannot be changed anymore?

Having an issue with latest version (updated yesterday in my VS2017- 15.8.9):
Cannot modify output directories in the properties window:
image
The fields seem to be read-only and the Combo shows Properties but I cannot change the values....
Is this just me?

Any idea?

MySQL question?

Is it possible to use this extension if database provider is MySQL? Or it is locked to MS SQL only?

Table with two Primary keys not generated properly in context

Visual Studio 15.7.5
Entity Framework Visual Editor 1.2.2.1
Using EFCore

I have three tables:
Site, Investigator, and a join table to link the two (for many-to-many relationship)
The join table just has InvestigatorId and SiteId properties, and I set them both to Identity = True

The generated context does this:

modelBuilder.Entity<EFCoreDesignTools.JoinSiteInvestigator>()
            .ToTable("JoinSiteInvestigators")
            .HasKey(t => new { t.public Int32 InvestigatorId!, t.public Int32 SiteId! });

Should be:

modelBuilder.Entity<EFCoreDesignTools.JoinSiteInvestigator>()
            .ToTable("JoinSiteInvestigators")
            .HasKey(t => new { t.InvestigatorId, t.SiteId });

Generate model clasess from code ?

Its possible to generate code from code ?

Could U guide how it is possible ?
I have own metamodel that I put in DB!
And i want to make enterprise ORm genrator

image

generating tables and coulmns are ready, further need generation of class models and ientityconfiguration

VS2017 Crash

Created a simple model with 2 entities and a 1 to many association. Selecting either entity and then selecting the Association Sources (or Targets) entry and then clicking on the Properties window dropdown for 'End2 Multiplicity' (which is currently set to 'ZeroMany') causes VS2017 to crash.

Foreign Keys not named correctly on code generation

Similar to my last one, sort of.

Same three tables:
image

in the context, it generates:

modelBuilder.Entity<EFCoreDesignTools.JoinSiteInvestigator>()
    .HasOne(x => x.Site)
    .WithOne()
    .HasForeignKey("Site_Id")
    .IsRequired().OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<EFCoreDesignTools.JoinSiteInvestigator>()
    .HasOne(x => x.Investigator)
    .WithOne()
    .HasForeignKey("Investigator_Id")
    .IsRequired().OnDelete(DeleteBehavior.Cascade);

.HasForeignKey("Site_Id") and .HasForeignKey("Investigator_Id") should be generated as "SiteId" and "InvestigatorId" respectively.

I'm not sure if this is an issue with how the relationships are set up, or an issue with the generator?

Feature Request - When renaming tables/columns add annotations so Add-Migration catches the rename

This is probably a very large ask, but I just renamed a table and some fields in the designer. When I went to Add-Migration, it dropped/created a new table instead of renaming.
According to this: https://stackoverflow.com/questions/49799627/rename-a-foreign-key-in-entity-framework-core-without-dropping-data/49802766#49802766

The way to do it is add annotations first, add the migration, and then rename the properties.

Thoughts? It isn't too hard to manually edit the Up method of the migration myself, but I figure if someone does a lot of changes, or has a large database, it could be useful.

Generated code not being output to the override output directory

I created a separate project for the model and created subdirectories (Entities, Enums and Context). Apart from the general object output directory, which is set to Entities, I also set an output directory per entity.

I have an entity called Address and the output directory is set to Entities/PartyAddresses, this directory exists and this was an option inside the combobox.

Upon code generation all entities get generated to the root of the Entities folder.

Error in tt files

image

This is present:
<#@ template inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation" debug="true"
hostSpecific="true" language="C#" compilerOptions="/langversion:latest"#>

Namespace collision in generated code

I think that it is common for developers to want to name an entity with the same name as part of the project namespace. Ex: I am currently working on a press release application. The project name is PressRelease. My root namespace is PressRelease as well. It is desirable to have an entity named PressRelease, but the generated code will then have numerous errors due to the collision. In my case, ModelClass.FullName for my Stage enum returns "PressRelease.EntityFramework.Model.Stage". In a number of places, this collides with the PressRelease entity name. If ModelClass.FullName could return "global::PressRelease.EntityFramework.Model.Stage" instead, it would avoid the collision.

I was almost able to work around the issue by changing the transform code, but I ran into ModelAttribute.FQPrimitiveType which can return int, bool, string, etc. in addition to my fully qualified class name. In C#, global::int is invalid. Inside FQPrimitiveType is the line: return modelEnum.FullName;, so fixing ModelClass.FullName should work. I realize that there is an argument to be made that says: "Don't do that!", but I believe that this would be a nice feature.

Support for complex types

It seems not possible (yet?) to add such cases in the designer.
One can add the first one but validation fails because of a missing Id property in the inheritance chain ... But I do not want one...
class Pos {
double x; double y;
}
Then of course I cannot add a property of type Pos since the type is not recognized...
class Foo {
int Id;
string Name;
Pos Where;
}

Is this something you exclude from the tool or just not here yet?

Thanks,

Concurrency mode: optimistic

Created a small model with Optimistic concurrency mode, using the default Timestamp as concurrency token property.
The generated code cannot be compiled due to generation of a line in several methods:

Timestamp = _timestamp;

where _timestamp is not declared at all, but it mentioned as parameter of the method in he documentation comment.

VS Crash on multiplicity changes

Trying to modify multiplicity of a *->1 relation, VS crashes and restarts...
This happens when trying to open the combo with (expected) other possible values.
Will try to have a simple case and/or vs logs...

Strange Issue - Generated code references an entity that is NOT referenced in the diagram

I am running into a very string issue. I have an EF diagram with out 14 entities, some with relationships and some without. There is one entity that no matter what I do it always is generated with a relationship to another entity that is not showing the designer (this includes even removing it and recreating it).

What can I do to track down what is causing this?

Using

  • Visual Studio 2017
  • .NET Core 2.1 project
  • Windows 10 x64

Concurrency token (Timestamp) in constructor parameters

The current implementation of the EFDesigner.ttinclude includes the TimeStamp conccurency token into the parameters of the public constructor with required data and also into the paras of the static Create method.

If I'm not mistaken there is no reaand son why a user should set the conccurency token property and EF core is taking care of this. Therefore I think that the conccurency token property should be excluded from the methods mentioned above.

Remark:
I happpy to share my modified EFDesigner.ttinclude and EFCoreDesigner.ttinclude files, but I at least for now I cant make a pull request, since I just use local copies of these files in my project and have not (yet) forked the EFDesigner project.

TPH

Hi it would be nice to have table splits and table per hierarchy support

Generate Enum attribute

How I can generate enum with Annotation [Display]? eg:

public enum Salary
{
[Display(Name="Paid Monthly")]
PaidMonthly = 1,
PaidYearly = 2
}

A couple of questions

Hi. great work.

1 - is biderectional relationships many to many ? if that's the case, how to use it, can't get it to work.

2 - in inheritance, what's the descriminator field ? it does not seem to mention it anywhere ?

NotImplementedException CultureInfo

Hi, I found a problem with the template. It tries to use my culture to do pluralization, but ended with a not implemented exception.

"Severity Code Description Project File Line Suppression State
Error Running transformation: System.NotImplementedException: The culture 'Czech (Czech Republic)' is not supported. Pluralization is currently only supported for the English language.
at System.Data.Entity.Design.PluralizationServices.PluralizationService.CreateService(CultureInfo culture)
at Microsoft.VisualStudio.TextTemplatingB1FB882D6FB23F37E071FAC15F790DB3D6CCE1885B7AE52C82326C4BE71A35610CEBC0A8943C91E048871F39722244F659C14ECF1A0B2A1C98B8AC0ACC30204E.GeneratedTextTransformation.WriteDbContextEFCore(ModelRoot modelRoot) in c:\program files (x86)\microsoft visual studio 2017\common7\ide\extensions\ljdqezoc.usq\TextTemplates\EFCoreDesigner.ttinclude:line 134
at Microsoft.VisualStudio.TextTemplatingB1FB882D6FB23F37E071FAC15F790DB3D6CCE1885B7AE52C82326C4BE71A35610CEBC0A8943C91E048871F39722244F659C14ECF1A0B2A1C98B8AC0ACC30204E.GeneratedTextTransformation.GenerateEFCore(Manager manager, ModelRoot modelRoot) in c:\program files (x86)\microsoft visual studio 2017\common7\ide\extensions\ljdqezoc.usq\TextTemplates\EFCoreDesigner.ttinclude:line 42
at Microsoft.VisualStudio.TextTemplatingB1FB882D6FB23F37E071FAC15F790DB3D6CCE1885B7AE52C82326C4BE71A35610CEBC0A8943C91E048871F39722244F659C14ECF1A0B2A1C98B8AC0ACC30204E.GeneratedTextTransformation.TransformText() in C:\Merz\Projekty\Git\CM\Magna.CM\Magna.CM.Database\DatabaseModel.tt:line 44 Miscellaneous Files c:\program files (x86)\microsoft visual studio 2017\common7\ide\extensions\ljdqezoc.usq\TextTemplates\EFCoreDesigner.ttinclude 134
"

Could you please catch the exception and force english pluralization ? Thank you !

Abstract/inherited/TPC =code still there for abstract class

Context: trying to see how to adapt usage of the tool for use with existing stuff (base classes provided by a internal framework)...

Created a model with an abstrat class AuditEntity that has Id/ChangedOn/ChangedBy properties.
Have classes in my model inherit from this.
Chose TPC for inheritance mapping...

  1. Yet there seems to be a dbset for this abstract class [I did not expect this] .

  2. When I create an new E_Application and do savechanges(), EF apparently tries to cast my E_application to an AuditEntity and fails.

I do not really know if the two symptoms are linked or separate issues or just wrong expectations/modeling by me...

image
image
image
image

Drag-drop issue after update of Designer and VS2017 - Error text good but wrong

Had an issue where I couldn't drag and drop an entity into the designer. Cropped up after updating EF Designer and then VS2017 (to 15.8.6, didn't fix when I updated to 15.8.7).

The error:

Drag drop operation failed with the following error:

Domain object with identity 05ea9a33-a0a8-4940-8a76-d870bb991325 was not found in directory.

A common cause of this exception is an out of date Visual Studio toolbox cache with respect to changes in your domain model. Run "devenv /setup" from the command line to reset this cache.

I tried doing that last bit: Running "devenv/setup" but it doesn't seem to work.
What ended up working was right-clicking the toolbox and selecting "Reset Toolbox", assuming the error is from EF designer maybe the text should be changed to suggest that?

.HasForeignKey in EF core 2.2 does not work

EFDesigner only claims compatibility with "Entity Framework Core 2.0 and 2.1" so maybe this shouldn't be an issue-- however I have been using EF Core 2.2 with EFDesigner release 1.2.6.21 and it was fine. Now with EFDesigner 1.2.6.23 my .generated context has .HasForeignKey in it, my program won't run, (has a problem in OnModelCreating). A quick google suggests also that EF core 2.2 has one or more breaking changes in the fluent API with .HasForeignKey vs EF core 2.1
error1

Generate diagram from DB

Can this be used to generate the initial diagram from an existing database providing a CNS?

Great project!

Recognize "Id" as primary key on import

I started trying this out today by importing a set of EF Core classes.

One thing that I had to do was to go through 50+ classes and mark the Id field as primary key.
EF Core automagically recognizes Id as being the primary key, so that doesn't need to be tagged by an attribute.
It would be practical if you could set an option to make EFDesigner do the same.

Enhancement: Default Default Constructor Visibility

The title is not a typo. I would like a new setting in the designer for Entity Model settings that will set the default visibility for the default constructor for all entities in the model. OData requires a public default constructor for POST operations. The second half of the feature would be in the code generation side where you could have something like:

public void WriteConstructor(ModelClass modelClass)
{
	Output("partial void Init();");
	NL();

	/***********************************************************************/
	// Default constructor
	/***********************************************************************/
			
	bool hasDefaultVisibility = GetDefaultVisibility() == null;
	bool hasRequiredParameters = GetRequiredParameters(modelClass, false).Any();
	string visibility = !hasDefaultVisibility && (hasRequiredParameters || modelClass.IsAbstract) ? "protected" :  GetDefaultVisibility();
...

Thanks for such an awesome effort and product.

Issue using with EF Core

I'm having an issue using it with EF Core.
I created a simple model with 5 tables, but the generated code is making calls that don't exist in Core:
modelBuilder.HasDefaultSchema(..)
EntityTypeBuilder<..>.ToTable(...)
etc.

Entity Framework Version is set to EFCore,
and the Nuget for Microsoft.EntityFrameworkCore(2.0.2)has been added to the class library project, which is .NET Core 2.0 project.

-BCC

InvalidCastException in MultipleOutputHelper.ttinclude

Hi, this is my first time submitting an issue on Github so let me know if I did anything wrong or if I need to provide more information.

I have a model with about 40 entities I've been designing and not sure when the error first showed up. I'm not even sure its really even a problem since I haven't looked over the code yet, but I started a new solution just to test and the error showed after saving the second entity. Didn't resolve after deleting the second entity, so hit ctrl-z unitl it was an empty canvas, and deleted the generated code for those entities and its still there.

Running transformation: System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'EnvDTE.ProjectItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{0B48100A-473E-433C-AB8F-66B9739AB620}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at Microsoft.VisualStudio.TextTemplating3246E923D3EAE737EADEB8472DF30160C46F1C6A28C09523326DEB23229A387D8DA775DCCD37FC548552E35F5D34C0A8931C74294263E74318F0438421180078.GeneratedTextTransformation.Manager.VSManager.GetCurrentState() in c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\rr1dks0x.21c\TextTemplates\MultipleOutputHelper.ttinclude:line 303
at Microsoft.VisualStudio.TextTemplating3246E923D3EAE737EADEB8472DF30160C46F1C6A28C09523326DEB23229A387D8DA775DCCD37FC548552E35F5D34C0A8931C74294263E74318F0438421180078.GeneratedTextTransformation.Manager.VSManager.ProjectSync(IEnumerable`1 keepFileNames) in c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\rr1dks0x.21c\TextTemplates\MultipleOutputHelper.ttinclude:line 246
at Microsoft.VisualStudio.TextTemplating3246E923D3EAE737EADEB8472DF30160C46F1C6A28C09523326DEB23229A387D8DA775DCCD37FC548552E35F5D34C0A8931C74294263E74318F0438421180078.GeneratedTextTransformation.Manager.VSManager.Process(Boolean split) in c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\rr1dks0x.21c\TextTemplates\MultipleOutputHelper.ttinclude:line 174
at Microsoft.VisualStudio.TextTemplating3246E923D3EAE737EADEB8472DF30160C46F1C6A28C09523326DEB23229A387D8DA775DCCD37FC548552E35F5D34C0A8931C74294263E74318F0438421180078.GeneratedTextTransformation.TransformText() in C:\Users\vaultboy\source\repos\LoadoutBuilder\LoadoutBuilderClasses\LoadoutBuilderModel.tt:line 50 Miscellaneous Files c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\rr1dks0x.21c\TextTemplates\MultipleOutputHelper.ttinclude 303

Concurrency mode: optimistic auto generated Timestamp property

2 separate, yet related bugs:

  1. When Concurrency is set to optimistic, and no property is marked as "Is Concurrency Token", the extension automatically creates a working Timestamp property, but the extension throws an error saying: "Entity1: Should have 1 concurrency properties but has 0".

  2. If you add a property and then mark it as "Is Concurrency Token" = True, the generated property has [Required] on it which causes validation errors on save. The UI does not allow you to change the Required = True setting.

OneToMany relation issue since upgrade to 1.2.6.23 with CS0102

Hi,

I today upgraded to version 1.2.6.23 (from 1.2.6.21 I believe). Since then I have an issue with one of my relations which worked fine before.
<unidirectionalAssociation Id="c4bfc1af-ccf6-4dfd-955c-489f6acf160f" sourceMultiplicity="ZeroMany" targetMultiplicity="One" targetPropertyName="Artikel" collectionClass="HashSet" sourceRole="Dependent" targetRole="Principal" foreignKeyLocation="None"> <modelClassMoniker Id="65a01e60-c158-4eaf-a9d9-4f1178f3699f" /> </unidirectionalAssociation>

This generates the definition of Artikel two times:

protected Backend.Data.Artikelstamm Artikel;
and

public Backend.Data.Artikelstamm Artikel { get {
which causes an error CS0102.

Did I do something wrong in the past or is this an issue with the new version? Thanks.

VS2017: The type initializer ... threw an exception

My VS2017 Community installation is crashing when trying to save a .efmodel
I have an EFcore class library project and added an EFModel, then changed the Entity Framework Version on the .efmodel to EFCore.
VS is already crashing when I try to select the Entity Framework Package Version.
When I ignore that and leave it on "Latest" then VS is crashing when I add an Entity and try to save the .efmodel file.

Following are the error log files. It looks like it doesn't find System.Net.Http

MSBuild_pid-4104_7d49ee7c2a2445fdb59f10eb992466b6.failure.txt
VsProjectFault_2e747c55-d05a-43a3-9498-3281a0f85deb.failure.txt

Additional info:
I had to install English language as it is a Swiss system and I first got an error about the language which is gone now.
Also I have to warnings stating
Cannot find a schema that defines target namespace 'http://schemas.microsoft.com/dsltools/EFModel'

Unique index not generated

Wanted a unique index on a string column[25], so selected both Indexed and unique index to true.
Index is created but the unique info seems to be ignored.

D.

Optimized NotifyPropertyChanged support

The current T4 files are generating code that calls OnPropertyChanged whenever the setter of a property is called (even if the value doesnt change). According to the example in How to: Implement the INotifyPropertyChanged Interface OnPropertyChanged is only called when there is a actual change of the value (also my personal preference since it avoids unecessary events).

I'm now using a modifed EFDesigner.ttinclude in my project which generates the following code for the properties:

      #region Property Name of type string
      [Required]
      protected string _Name;

      /// <summary>
      /// Required, Min length = 250
      /// </summary>
      public string Name
      {
         get {return _Name;}
         set {if (_Name != value) {string oldName=_Name; NameChanging(oldName, value);  _Name = value;OnPropertyChanged(nameof(Name)); NameChanged(oldName, value);}}
      }
      partial void NameChanging(string oldName, string newName);
      partial void NameChanged(string oldName, string newName);
      #endregion

Below is the modified method in the modified EFDesigner.ttinclude which I have included in my project. I has the improved OnPropertyChanged handling and it also excludes the ConccurencyToken from calling OnPropertyChanged.

void WritePersistentProperties(ModelClass modelClass)
{
   if (!modelClass.Attributes.Any(x => x.Persistent))
      return;

   Output("// Persistent properties");
   List<string> segments = new List<string>();
   NL();

   foreach (ModelAttribute modelAttribute in modelClass.Attributes.Where(x => x.Persistent))
   {
      string nullable = IsNullable(modelAttribute) ? "?" : "";

      Output($"#region {(modelAttribute.IsConcurrencyToken?"ConcurrencyToken":"Property")} {modelAttribute.Name} of type {modelAttribute.FQPrimitiveType}{nullable}");
      
	  segments.Clear();

      if (modelAttribute.IsIdentity)
         segments.Add("Identity");
      if (modelAttribute.Required || modelAttribute.IsIdentity)
         segments.Add("Required");
      if (modelAttribute.Indexed)
         segments.Add("Indexed");
      if (modelAttribute.MinLength > 0)
         segments.Add($"Min length = {modelAttribute.MinLength}");
      if (modelAttribute.MaxLength > 0)
         segments.Add($"Max length = {modelAttribute.MaxLength}");
      if (!string.IsNullOrEmpty(modelAttribute.InitialValue))
      {
         string quote = modelAttribute.PrimitiveType == "string" ? "\"" : modelAttribute.PrimitiveType == "char" ? "'" : "";
         segments.Add($"Default value = {quote}{FullyQualified(modelClass.ModelRoot, modelAttribute.InitialValue)}{quote}");
      }

     

      if (!modelAttribute.AutoProperty && !modelAttribute.IsConcurrencyToken)
      {
         GenerateClassAnnotations(modelAttribute, "_");
         Output($"protected {modelAttribute.FQPrimitiveType}{nullable} _{modelAttribute.Name};");

         NL();
      }

      if (!string.IsNullOrEmpty(modelAttribute.Summary) || segments.Any())
      {
         Output("/// <summary>");
         if (segments.Any())
            Output($"/// {string.Join(", ", segments)}");
         if (!string.IsNullOrEmpty(modelAttribute.Summary))
            Output("/// {0}", modelAttribute.Summary);
         Output("/// </summary>");
      }
      if (!string.IsNullOrEmpty(modelAttribute.Description))
      {
         Output("/// <remarks>");
         Output("/// {0}", modelAttribute.Description);
         Output("/// </remarks>");
      }

      string setterVisibility = modelAttribute.SetterVisibility == SetterAccessModifier.Protected ? "protected " : modelAttribute.SetterVisibility == SetterAccessModifier.Internal ? "internal " : "";

      if (modelAttribute.AutoProperty || modelAttribute.IsConcurrencyToken)
      {
         GenerateClassAnnotations(modelAttribute);
         Output($"public {modelAttribute.FQPrimitiveType}{nullable} {modelAttribute.Name} {{ get; {setterVisibility}set; }}");
      }
      else
      {

         Output($"public {modelAttribute.FQPrimitiveType}{nullable} {modelAttribute.Name}");
         Output("{");
         Output($"get {{return _{modelAttribute.Name};}}");
         Output($"{setterVisibility}set {{if (_{modelAttribute.Name} != value) {{{modelAttribute.FQPrimitiveType}{nullable} old{modelAttribute.Name}=_{modelAttribute.Name}; {modelAttribute.Name}Changing(old{modelAttribute.Name}, value);  _{modelAttribute.Name} = value;OnPropertyChanged(nameof({modelAttribute.Name})); {modelAttribute.Name}Changed(old{modelAttribute.Name}, value);}}}}");
         Output("}");
      
	     Output($"partial void {modelAttribute.Name}Changing({modelAttribute.FQPrimitiveType}{nullable} old{modelAttribute.Name}, {modelAttribute.FQPrimitiveType}{nullable} new{modelAttribute.Name});");
	     Output($"partial void {modelAttribute.Name}Changed({modelAttribute.FQPrimitiveType}{nullable} old{modelAttribute.Name}, {modelAttribute.FQPrimitiveType}{nullable} new{modelAttribute.Name});");
	  }

	   Output("#endregion");
      NL();
   }

   if (!modelClass.AllAttributes.Any(x => x.IsConcurrencyToken) && 
       (modelClass.Concurrency == ConcurrencyOverride.Optimistic || modelClass.ModelRoot.ConcurrencyDefault == Concurrency.Optimistic))
   {
      Output("/// <summary>");
      Output("/// Concurrency token");
      Output("/// </summary>");
      Output("[Timestamp]");
      Output("public Byte[] Timestamp { get; set; }");
      NL();
   }
}

WillCascadeOnDelete not working with EF Core

Hi
When I define relations between entities and set End 1 on delete resp. End 2 on delete to Cascade or None the EFDesigner creates a .WillCascadeOnDelete(true/false). This did not compile on my system. AFIK WillCascadeOnDelete does not exist for EF core (it does in EF6) and OnDelete(DeleteBehavior) has to be used for EF Core.

Replacing the code to generate WillCascadeOnDelete for the for undirectionalassociations with

switch(association.SourceDeleteAction) {
  case DeleteAction.Default:
    //Nothing to do
    break;
  case DeleteAction.Cascade:
    segments.Add("OnDelete(DeleteBehavior.Cascade)");
    break;
  case DeleteAction.None:
    segments.Add("OnDelete(DeleteBehavior.Restrict)");
    break;
}

and for the bidirectionalassociations with

switch(association.SourceDeleteAction) {
  case DeleteAction.Default:
    //Nothing to do
    break;
  case DeleteAction.Cascade:
    segments.Add("OnDelete(DeleteBehavior.Cascade)");
    break;
  case DeleteAction.None:
    segments.Add("OnDelete(DeleteBehavior.Restrict)");
    break;
}

in the EFCoreDesigner.ttinclude seems to fix the problem. Not sure if this would be valid for all use cases.

Small side note:
I'm not sure if I got this right, but for Bidirectionalassociations the docu on End 1 on delete resp. End 2 on delete says How to handle objects on this end if the object on the other end is deleted. However the T4 files for EF core, seem to handle this more like How to handle objects on the other end if the object on this end is deleted.

Cascade delete

Was trying to define a recursive relation. one-to-many from T to T.
When I validate I get no issue but on db creation I get exception saying I should add ON CASCADE DELETE NOACTION...

Looks like the code options on the relation in the editor does something when set to CASCADE but nothing when set to NONE. [EF6] Which IMHO should be the reverse since EF6 cascades by default. Or the generated code should always add a WillCascadeOn() call with true/false without relying on the default.

I do not know the defaults for EF Core..

Setting the relation ends to CASCADE, then passing false , in place of nothing, into generated code allows the db to be created. Am I doing something wrong or missig something?

Version: 1.2.2.1

And kudos for such a nice tool.

Thanks,
D.

Properties generating isUnicode(...) / varchar vs. nvarchar

wanted to get some guidance on best approach for handing ANSI / varchar vs. Unicode / nvarchar for property to column mappings. Best I can determine is to specify [Column(TypeName="varchar")] or [Column(TypeName="nvarchar")] as a custom attribute in the property. Is there a more elegant way to do this?

Don't create DbSets for many to many linking tables?

It looks like in generally, you don't create DbSets for linking tables in many to many relationships in EF core.

On both the EF core docs: https://docs.microsoft.com/en-us/ef/core/modeling/relationships#other-relationship-patterns
and in "EF Core in Action" by Jon Smith (which I'm currently reading) neither create a DbSet for that table.

Two questions - do you know why that is (neither explain it that I've seen)? And, if there a way to configure EFDesigner to do that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.