ardalis / Specification

Base class with tests for adding specifications to a DDD model
MIT License
1.93k stars 246 forks source link

Cannot save data with Backing Field #400

Closed datnt97 closed 1 month ago

datnt97 commented 4 months ago

I cannot save data for the class MyEntityNotWork because the Backing Field is not the camel case of the field. For the class MyEntity, it's working.

Did I do anything wrong?

public class MyEntityNotWork
{
  public string Data
  {
    get => IsCompressed ? _dataTest.Decompress() : _dataTest;
    private set => _dataTest = value;
  }

  public string StyleData
  {
    get => IsCompressed ? _styleTest.Decompress() : _styleTest;
    private set => _styleTest = value;
  }

  public string Config
  {
    get => IsCompressed ? _configTest.Decompress() : _configTest;
    private set => _configTest = value;
  }
}
public class MyEntity
{
  public string Data
  {
    get => IsCompressed ? _data.Decompress() : _data;
    private set => _data = value;
  }

  public string StyleData
  {
    get => IsCompressed ? _styleData.Decompress() : _styleData;
    private set => _styleData = value;
  }

  public string Config
  {
    get => IsCompressed ? _config.Decompress() : _config;
    private set => _config = value;
  }
}
fiseni commented 1 month ago

Hi @datnt97,

You should cross-check your EF configuration. This library does not affect your EF model in any way. Refer to the following EF docs regarding backing fields. https://learn.microsoft.com/en-us/ef/core/modeling/backing-field?tabs=data-annotations