locked
How to automatically assign content RRS feed

  • Question

  • User1655654435 posted

    I use ef core and I have a property in my model that usually is set to a certain value. I'm wondering if I can auto assign this property to this value, so that when I save the table this property is automatically set?

    public string Language { get; set; } = "No";

    Would this even work and is it bad practice to do stuff like this in the data models? I also want to be able to change this value if I need to do it. 

    Monday, December 10, 2018 1:56 PM

All replies

  • User475983607 posted

    bluMarmalade

    I use ef core and I have a property in my model that usually is set to a certain value. I'm wondering if I can auto assign this property to this value, so that when I save the table this property is automatically set?

    public string Language { get; set; } = "No";

    Would this even work and is it bad practice to do stuff like this in the data models? I also want to be able to change this value if I need to do it. 

    The syntax shown initializes a property.  The following reference docs explains the details.

    https://docs.microsoft.com/en-us/dotnet/csharp/properties

    The Language property can be changed to whatever you like after the class has initialized. 

    Monday, December 10, 2018 2:11 PM