ASP .NET Core - How to tell if data contract property was not set or set to null

blcook223

In ASP .NET Core, given a controller method for a PATCH endpoint like this:

[HttpPatch]
[Route("{entity_id}")]
public async Task<IActionResult> UpdateEntity(
    [FromRoute(Name = "entity_id")]int entity_id,
    [FromBody(Name = "")]EntityUpdate entityUpdate,
    CancellationToken cancellationToken
)
{
    await UpdateEntity(
        entity_id,
        entityUpdate,
        cancellationToken
    );
    return Ok();
}

And the following definition for EntityUpdate:

[DataContract(Name = "entity_update")]
public class EntityUpdate 
{
    [DataMember(Name = "name")]
    public string Name { get; set; }

    [DataMember(Name = "description")]
    public string Description { get; set; }
}

Is there anyway to tell if a given property of EntityUpdate was explicitly set by the client to null or simply omitted?

Daniel A. White

I forgo the autoproperty and include a Changed property.

[DataContract(Name = "entity_update")]
public class EntityUpdate 
{
    private string _name;
    private bool _nameChanged;
    [DataMember(Name = "name")]
    public string Name { get => _name; set { _name = value; _nameChanged = true; } }

    [DataMember(Name = "description")]
    public string Description { get; set; }
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to set up Automapper in ASP.NET Core

分類Dev

.Net Core cookie will not be set

分類Dev

ASP.Net Core, Create Model with Complex Data Type Property

分類Dev

VSTS/TFS set environment variable ASP.NET core

分類Dev

How to differentiate between null and non existing data in JSON in Asp.Net Core model binding?

分類Dev

How to set SwipeRefreshLayout refreshing property using android data binding?

分類Dev

How to set SwipeRefreshLayout refreshing property using android data binding?

分類Dev

How to set SwipeRefreshLayout refreshing property using android data binding?

分類Dev

How to set column NOT NULL?

分類Dev

How to set default datetime format for .net core 2.0 webapi

分類Dev

How to set ASP.NET 5 environment variables on production environment

分類Dev

How to set default button in ASP.Net MVC

分類Dev

How To Set Background None Color ASP.NET C#

分類Dev

How to set JavaScript variable to ASP.NET Session?

分類Dev

How to set tab index for url in asp.net

分類Dev

TypeError: Cannot Set property 'onclick' of null

分類Dev

Uncaught Typeerror: Cannot set property innerHTML of null

分類Dev

How to pass primitive data to asp.net core middleware

分類Dev

How to Pass View Data to Partial View in Asp.net core?

分類Dev

ASP.NET Control assign to property null

分類Dev

ReactJS - How to set property on window?

分類Dev

How to set value to a property in Scala

分類Dev

Set up Dependency Injection on Service Fabric using default ASP.NET Core DI container

分類Dev

Set Page from Area Folder as default page in asp.net core 2.2 MVC

分類Dev

asp.net core 2.2 is not using ConnectionString set in WebApp Azure config

分類Dev

How to tell if code is written for regular .NET or .NET Core?

分類Dev

How to set form value to NULL

分類Dev

How to set groupId to null in @KafkaListeners

分類Dev

How to set collection to null in Blueprism

Related 関連記事

  1. 1

    How to set up Automapper in ASP.NET Core

  2. 2

    .Net Core cookie will not be set

  3. 3

    ASP.Net Core, Create Model with Complex Data Type Property

  4. 4

    VSTS/TFS set environment variable ASP.NET core

  5. 5

    How to differentiate between null and non existing data in JSON in Asp.Net Core model binding?

  6. 6

    How to set SwipeRefreshLayout refreshing property using android data binding?

  7. 7

    How to set SwipeRefreshLayout refreshing property using android data binding?

  8. 8

    How to set SwipeRefreshLayout refreshing property using android data binding?

  9. 9

    How to set column NOT NULL?

  10. 10

    How to set default datetime format for .net core 2.0 webapi

  11. 11

    How to set ASP.NET 5 environment variables on production environment

  12. 12

    How to set default button in ASP.Net MVC

  13. 13

    How To Set Background None Color ASP.NET C#

  14. 14

    How to set JavaScript variable to ASP.NET Session?

  15. 15

    How to set tab index for url in asp.net

  16. 16

    TypeError: Cannot Set property 'onclick' of null

  17. 17

    Uncaught Typeerror: Cannot set property innerHTML of null

  18. 18

    How to pass primitive data to asp.net core middleware

  19. 19

    How to Pass View Data to Partial View in Asp.net core?

  20. 20

    ASP.NET Control assign to property null

  21. 21

    ReactJS - How to set property on window?

  22. 22

    How to set value to a property in Scala

  23. 23

    Set up Dependency Injection on Service Fabric using default ASP.NET Core DI container

  24. 24

    Set Page from Area Folder as default page in asp.net core 2.2 MVC

  25. 25

    asp.net core 2.2 is not using ConnectionString set in WebApp Azure config

  26. 26

    How to tell if code is written for regular .NET or .NET Core?

  27. 27

    How to set form value to NULL

  28. 28

    How to set groupId to null in @KafkaListeners

  29. 29

    How to set collection to null in Blueprism

ホットタグ

アーカイブ