Replies: 1 comment
-
If you choose to use private backing fields instead of managed backing fields, then you must manually get/set the state into the serialization stream like this: [Serializable]
public class NOChargeReason : BusinessBase<NOChargeReason>
{
public static readonly PropertyInfo<string> ReasonProperty = RegisterProperty<string>(nameof(Reason), RelationshipTypes.PrivateField);
private string _reason = ReasonProperty.DefaultValue;
public string Reason
{
get => GetProperty(ReasonProperty, _reason);
set => SetProperty(ReasonProperty, ref _reason, value);
}
protected override void OnSetState(SerializationInfo info, StateMode mode)
{
base.OnSetState(info, mode);
_reason = info.GetValue<string>(nameof(_reason));
}
protected override void OnGetState(SerializationInfo info, StateMode mode)
{
info.AddValue(nameof(_reason), _reason);
base.OnGetState(info, mode);
}
} This is why I always recommend using managed backing fields, as they are automatic. public static readonly PropertyInfo<string> ReasonProperty = RegisterProperty<string>(nameof(Reason));
public string Reason
{
get => GetProperty(ReasonProperty);
set => SetProperty(ReasonProperty, value);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Discussed in #2126
Originally posted by Art666OTS February 26, 2021
I found an article on CSLA Simple Service Implementation with CSLA.NET and thought what a great mechanism.
I have a web site that uses CSLA and it works fine. I have an updated version of this web site that uses a Business Library as described in the article and it also works fine.
Now I have created an API with the same Business Library but it only partially works. I can read entries from the database but I cannot update/insert them.
When I try to do this the parameters are all set to the default values not the values I have just entered. Below are some code fragments
Code for setting properties
Code for setting up parameters for Insert.
Sample of the code for a property
Any assistance would be greatly appreciated.
Arthur
Beta Was this translation helpful? Give feedback.
All reactions