IntelliTect / Coalesce

Quickly build amazing web apps
https://intellitect.github.io/Coalesce/
Apache License 2.0
64 stars 22 forks source link

ForeignKey properties in inherited types no longer discovered. #63

Closed adamskt closed 6 years ago

adamskt commented 6 years ago

This is broken in 4fc35f4216509324e25e2d468a60219c5598d3e0 In prior versions several entities could share a base class with a foreign key property and related navigation property decorated with the [ForeignKey(nameof(fkey_property))] and code generation would proceed as normal. In versions after 2.0.0-alpha-270, errors like the following are displayed and code generation fails:

Starting Coalesce 2.0.0-alpha-271, running under .NETCoreApp,Version=v2.0 https://github.com/IntelliTect/Coalesce

Working in 'D:\Dev\SouthernCross-VSO\AMIPortal', using 'coalesce.json' [i:0.171] Loading Projects: [i:0.191] D:\Dev\SouthernCross-VSO\AMIPortal\src\SouthernCross.AmiPortal.Web\SouthernCross.AmiPortal.Web.csproj [i:0.192] D:\Dev\SouthernCross-VSO\AMIPortal\src\SouthernCross.AmiPortal.Data\SouthernCross.AmiPortal.Data.csproj [i:4.160] Gathering Types [i:5.582] Analyzing 31 Types [e:6.493] Failure: SouthernCross.AmiPortal.Data.Models.Customer.LastWorker : SouthernCross.AmiPortal.Data.Models.Worker: No ID Property found for related object. Related object needs a foreign key that matches by name or is marked with the [ForeignKey] attribute. [e:6.494] Failure: SouthernCross.AmiPortal.Data.Models.CustomerContact.LastWorker : SouthernCross.AmiPortal.Data.Models.Worker: No ID Property found for related object. Related object needs a foreign key that matches by name or is marked with the [ForeignKey] attribute. [e:6.495] ** Failure: SouthernCross.AmiPortal.Data.Models.ElectricMeterExchange.LastWorker : SouthernCross.AmiPortal.Data.Models.Worker: No ID Property found for related object. Related object needs a foreign key that matches by name or is marked with the [ForeignKey] attribute. [e:6.497] Model validation failed. Exiting.

Customer, CustomerContact, ElectricMeterExchange all inherit from WorkOrderBase that has these properties:

        public short? LastWorkerId { get; set; }

        [ForeignKey(nameof(LastWorkerId))]
        public Worker LastWorker { get; set; }
ascott18 commented 6 years ago

Oops. Parent vs EffectiveParent. Perhaps I should come up with better names for those. EffectiveParent is arguably more useful most of the time, but I didn't want to change Parent from what it has always been.

Parent is the class that the property is declared on. EffectiveParent is the class that we're trying to look at that may have inherited some properties from a base class. Perhaps I'll change EffectiveParent to Parent, and Parent to DeclaringClass or DeclaringParent or something.

adamskt commented 6 years ago

Yeah, I think there is an issue open to rename all the props so we don't collide with potential props on the EF entities.

ascott18 commented 6 years ago

Well, these are just internal properties on PropertyViewModel. When I refactored some stuff this weekend I used one when I should have used the other.