Open jpiquot opened 6 years ago
The procurement type entity class is :
using Administration;
using Framework.Model;
using GlobalAddressBook;
using Inventory;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using WarehouseManagement;
namespace Procurement
{
/// <summary>
/// The procurement type
/// <para>Type de demande d'approvisionnement</para>
/// </summary>
/// <remarks>
/// Defines also defauts for the warehouse procurement header.
/// <para>Le type d'approvisionnement défini aussi les paramètres par défaut de l'entête de la demande d'approvisionnement.</para>
/// </remarks>
public class ProcurementType : DataEntity
{
/// <summary>
/// Required hierarchy node identifier.
/// </summary>
/// <remarks>If defined, only items in the defined hierarchy node can be added to the warehouse procurement</remarks>
public int? HierarchyNodeId { get; set; }
/// <summary>
/// Required inventory item identifier.
/// </summary>
/// <remarks>
/// If defined, only the defined item can be added to the warehouse procurement. For exemple, we want to define a procurement of an item for
/// many wharehouses.
/// </remarks>
public int? InventoryItemId { get; set; }
/// <summary>
/// Required source site identifier.
/// </summary>
/// <remarks>If defined, only items available on this site can be added to the warehouse procurement</remarks>
public int? SourceSiteId { get; set; }
/// <summary>
/// Required destination warehouse identifier.
/// </summary>
/// <remarks>If defined, only procurements for this warehouse can be added</remarks>
public int? WarehouseId { get; set; }
#region Relations
/// <summary>
/// Required hierarchy node.
/// </summary>
/// <remarks>If defined, only items in the defined hierarchy node can be added to the warehouse procurement</remarks>
[ForeignKey(nameof(HierarchyNodeId))]
public HierarchyNode HierarchyNode { get; set; }
/// <summary>
/// Required inventory item.
/// </summary>
/// <remarks>If defined, only the defined item can be added. For exemple, we want to define a procurement of an item for many wharehouses.</remarks>
[ForeignKey(nameof(InventoryItemId))]
public InventoryItem InventoryItem { get; set; }
/// <summary>
/// Procurements list
/// <para>Liste de demandes d'approvisionnement</para>
/// </summary>
[InverseProperty(nameof(WarehouseProcurement.ProcurementType))]
public ICollection<WarehouseProcurement> Procurements { get; set; }
/// <summary>
/// Required source site.
/// </summary>
/// <remarks>If defined, only items available on this site can be added to the warehouse procurement</remarks>
[ForeignKey(nameof(SourceSiteId))]
public Site SourceSite { get; set; }
/// <summary>
/// Required destination warehouse.
/// </summary>
/// <remarks>If defined, only procurements for this warehouse can be added to the warehouse procurement</remarks>
[ForeignKey(nameof(WarehouseId))]
public Warehouse Warehouse { get; set; }
#endregion Relations
}
}
If i don't do expand select, everything works :
{
"@odata.context": "http://localhost:5000/odata/$metadata#ProcurementTypes",
"@odata.count": 6,
"value": [
{
"@odata.etag": "W/\"YmluYXJ5J0FBQUFBQUFBRlRjPSc=\"",
"RowVersion": "AAAAAAAAFTc=",
"Id": 1,
"HierarchyNodeId": 3,
"InventoryItemId": null,
"SourceSiteId": null,
"WarehouseId": null,
"Alias": null,
"Code": "LIVREA",
"Description": "Réassort de livres sur la plateforme",
"Name": "Réassortiments livres",
"ShortName": "Réassort Liv.",
"CreatedById": "jpiquot",
"CreatedDateTime": "2018-06-25T07:14:23.4372837+02:00",
"ModifiedById": null,
"ModifiedDateTime": null,
"Warehouse": null,
"InventoryItem": null
},
{
"@odata.etag": "W/\"YmluYXJ5J0FBQUFBQUFBRlRnPSc=\"",
"RowVersion": "AAAAAAAAFTg=",
"Id": 2,
"HierarchyNodeId": 3,
"InventoryItemId": null,
"SourceSiteId": null,
"WarehouseId": null,
"Alias": null,
"Code": "LIVNPTF",
"Description": "Approvisionnement des nouveautés livres sur la plateforme",
"Name": "Approvisionnement nouveautés livres",
"ShortName": "Nouv. Liv. PTF",
"CreatedById": "jpiquot",
"CreatedDateTime": "2018-06-25T07:14:23.4478773+02:00",
"ModifiedById": null,
"ModifiedDateTime": null,
"Warehouse": null,
"InventoryItem": null
},
{
"@odata.etag": "W/\"YmluYXJ5J0FBQUFBQUFBRlRrPSc=\"",
"RowVersion": "AAAAAAAAFTk=",
"Id": 3,
"HierarchyNodeId": 3,
"InventoryItemId": null,
"SourceSiteId": null,
"WarehouseId": null,
"Alias": null,
"Code": "LIVNPDV",
"Description": "Envoi des nouveautés livres dans les points de vente",
"Name": "Nouveauté livres PDV",
"ShortName": "Nouv. Liv. PDV",
"CreatedById": "jpiquot",
"CreatedDateTime": "2018-06-25T07:14:23.4479304+02:00",
"ModifiedById": null,
"ModifiedDateTime": null,
"Warehouse": null,
"InventoryItem": null
}
]
}
@jpiquot I did a quick test, it works fine at my side:
Would you please share me a repro to dig more?
If I do this request : http://localhost:5000/odata/WarehouseProcurements/?$expand=Warehouse&$top=1
It is OK :
{"@odata.context":"http://localhost:5000/odata/$metadata#WarehouseProcurements","value":[{"@odata.etag":"W/\"YmluYXJ5J0FBQUFBQUFBaVpjPSc=\"","RowVersion":"AAAAAAAAiZc=","Id":1,"Cancelled":false,"HierarchyNodeId":null,"InventoryItemId":null,"ProcurementTypeId":1,"SendManually":false,"SourceSiteId":null,"Status":"New","WarehouseId":null,"Alias":null,"Code":"WP0013","Description":null,"Name":"R\u00e9assort Liv. Candice","ShortName":"R\u00e9assort Liv.","CreatedById":"jpiquot","CreatedDateTime":"2018-07-04T15:41:56.7946241+02:00","ModifiedById":null,"ModifiedDateTime":null,"Warehouse":null}]}
If I add the Name field in the select clause of the expanded entity, I will have an error 500. http://localhost:5000/odata/WarehouseProcurements/?$expand=Warehouse($select=Name)&$top=1
Maybe it works for you as you have one of the records in the result set with a non null value. Could you try with all null?
This is a EF Model issue in my application. The issue can be closed.
Same here, EF Model issue. A field that cannot be null in my model but in DB was save like null
Versions :
NullReferenceException is thown when calling this OData request :
Method : ODataQueryOptions/LimitResults
Arguments : queryable.ElementType :
limit = 1000
queryable =
Stack trace :