Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoInferImplements #102

Closed
ghost opened this issue Feb 9, 2021 · 2 comments
Closed

AutoInferImplements #102

ghost opened this issue Feb 9, 2021 · 2 comments

Comments

@ghost
Copy link

ghost commented Feb 9, 2021

Good afternoon from Hamilton, NZ.

I have the latest source up to and including the fix for issue #99

The problem I have found has an example in the Beef.Demo sample code. In Beef.Demo.xml the Product entity has AutoInferImplements set to true and an "Id" field of type int:

<Entity Name="Product" Text="Product" Collection="true" CollectionResult="true" AutoInferImplements="false" WebApiRoutePrefix="api/v1/products" DataSvcCaching="false" AutoImplement="OData" ODataName="TestOData" ODataEntity="Model.Product" ODataCollectionName="Products">
    <Property Name="Id" Text="{{Product}} identifier" Type="int" Immutable="true" UniqueKey="true" DataName="ID" EmitDefaultValue="true" />

However, in the generated code in Entities\Generated\Product.cs the class definition still expects the implementation of IIntIdentifier:

public partial class Product : EntityBase, IIntIdentifier, IUniqueKey, IEquatable<Product>

Looking in \tools\Beef.CodeGen.Core\Config\Entity\EntityConfig.cs we see:

        private void InferImplements()
        {
            if (ImplementsAutoInfer.HasValue && !ImplementsAutoInfer.Value)
                return;

and then

                var iid = id.Type switch
                {
                    "Guid" => "IGuidIdentifier",
                    "int" => "IIntIdentifier",

I think something is happening in the xml->yaml->json translation. Maybe do do with here:
(ConfigType.Entity, ConfigurationEntity.Entity, "AutoInferImplements", "implementsAutoInfer"),
and/or here:

        [JsonProperty("autoInferImplements", DefaultValueHandling = DefaultValueHandling.Ignore)]
        [PropertySchema("Entity", Title = "Indicates whether to automatically infer the interface implements for the entity from the properties declared.",
            Description = "Will attempt to infer the following: `IGuidIdentifier`, `IIntIdentifier`, `IStringIdentifier`, `IETag` and `IChangeLog`. Defaults to `true`.")]
        public bool? ImplementsAutoInfer { get; set; }

Cheers,
Damian.

chullybun added a commit that referenced this issue Feb 9, 2021
chullybun added a commit that referenced this issue Feb 9, 2021
* Rename ResultHandling.Stop to ResultHandling.ThrowException - this is the more meaningful name. The host will then decide on how to handle.

* Fix Issue #102

* Update template solution.
Re-publish Beef.Core - merge challenge.
@chullybun
Copy link
Collaborator

Hi @damiankennedy2012 and hello Hamilton - certainly miss good 'ol NZ :-)

I have fixed the issue you identified. Grab the latest packages and verify.

Cheers...

@ghost
Copy link
Author

ghost commented Feb 11, 2021

Hi,
Yes, cheers, can confirm it is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant