Ends in:
2 DAYS
5 HRS
41 MIN
2 SEC
Ends in:
2 D
5 H
41 M
2 S
Open Closed

Creating a required 1-n navigation property in ABP Suite causes errors #6111


User avatar
0
sid@extranerds.com created
  • ABP Framework version: v7.4.0
  • UI Type: Blazor Server
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

Quick background. My app relates to the exchange of foreign currencies. I have two entities... a "Currency" (eg. UD dollar, Japanese Yen, etc.) and a "CurrencyPair" (eg. USD/JPY, EUR/USD, etc.). So I have a "Currency" entity with a GUID ID and a name (eg. "USD", "EUR", "JPY", etc.), and I have a "CurrencyPair" entity with a GUID ID and a name (e. "EUR/USD", "USD/JPY", etc.). I created both entities. At this point, there is no relationship between them, and each entity only has an ID and a Name. I was able to "Save and Generate" these entities, which built the code. And I ran the app with no issues.

Now I am trying to define the navigation properties. A "CurrencyPair" must reference two "Currency" entities. For the currency pair called "USD/JPY", "USD" is called the "quote" currency and "JPY" is referred to as the "base" currency. So I have two navigation properties I need called "QuoteCurrency" and "BaseCurrency". So, I defined these as follows when defining the navigation properties on the "CurrencyPair" entity:

  1. On the "Basic" tab I selected "Currencies.cs" for the Entity.
  2. For Display Property I selected "Name".
  3. I toggled the "Required" checkbox ON.
  4. On the "Advanced" tab the only thing I changed was to rename Property Name in the Others section from "CurrencyId" to "QuoteCurrencyId"
  5. I repeated the above steps for the "base" currency navigation property, thus renaming "CurrencyId" to "BaseCurrencyId"
  6. I clicked "Save and Generate"

ABP, after several seconds, produced this error: Error occurred on DB migration step! Make sure the project is compiled and working. Command output: Build started... Build failed. Use dotnet build to see the errors.

Using ABP Suite to define an entity with a 1-n navigation property that is flagged as required... It seems that any time I flag a navigation property as "required" ABP Suite will fail to "Save and generate" the code. When it attempts to, I receive the error provided above. Interestingly, If I remove the required flag on these navigation properties, the issue goes away. If I check the "required" box and try again the error comes back. After seeing this error I switched over to Visual Studio and tried to build the solution. This is what I see.

The issue appears to be with this line of generated code: <Select TValue="Guid"

If I manually change it to: <Select TValue="Guid?"

... in other words, make it nullable, now the solution builds without errors.

Shouldn't this be defined as Guid? always, even if the navigation property is required? This is select item for a filter. Although a value for this property is required in the entity definition, it shouldn't be required to filter by this property. Or may there's something I don't understand about this. Please clarify if you can.

At any rate, vanilla code produced by ABP Suite (before any custom modifications) should not produce ABP Suite and build errors... unless I'm doing something wrong. Please advise.


1 Answer(s)
  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi, thanks for reporting this issue. We have fixed it and it will be available with v7.4.2 or v8.0.0 (depending on the next release):

    I close the question since the problem you have reported has been fixed and will be available with the next release.

    Btw, I have refunded your ticket. Regards.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 02, 2024, 12:35