Comments (7)
This is because MobileFormatter
has no concept of the NonSerialized
attribute, nor any way to flag a property so it is not serialized.
Right now your workaround is to use a managed property, not a private backing field, and allow it to serialize.
from cslaforum.
Thanks, that explains it. Although, I am a bit confused how the normal serialization for saving of object then works which is also using the MobileFormatter?
from cslaforum.
No, you are right - this isn't a MobileFormatter
thing at all.
The problem is this line that calls LoadProperty.
Or more accurately a limitation of the overloads of LoadProperty
in the ObjectFactory
class:
https://github.com/MarimerLLC/csla/blob/master/Source/Csla.Shared/Server/ObjectFactory.cs#L120
Your property is truly read-only - it has no setter, and it uses a private backing field, so the LoadProperty
method has absolutely no way to set the value of the property.
I do think this is related somewhat to the limitation of MobileFormatter
where we have no way to mark a property as "nonserialized". No way to indicate that the property should be ignored.
The workaround thus far has been that such a property shouldn't be managed at all. If there's no registered IPropertyInfo
for a property it is ignored by pretty much everything (except BinaryFormatter and NDCS, which follow their own rules).
from cslaforum.
Does this mean that with the MobileFormatter that this property will be serialized when doing a normal save operation? Or is that determined by the OnGetState and OnSetState methods for private fields?
I just want to make sure that there is no unnecessary data serialized and at the same time want to have the csla property info fields for binding support.
from cslaforum.
@JacoJordaan regarding serialization, I'm pretty confident that the private backing field is not serialized unless you explicitly implement the onget/onset state overrides and manually move the field value through the serialization stream.
This code establishes that the City
value is not cloned.
using Csla;
using System;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
var obj1 = DataPortal.Create<PersonEdit>();
obj1.Name = "Rocky";
obj1.City = "Eden Prairie";
var obj2 = obj1.Clone();
Console.WriteLine($"clone Name {obj2.Name}");
Console.WriteLine($"clone City {obj2.City}");
Console.ReadLine();
}
}
[Serializable]
public class PersonEdit : BusinessBase<PersonEdit>
{
public static readonly PropertyInfo<string> NameProperty = RegisterProperty<string>(nameof(Name));
public string Name
{
get => GetProperty(NameProperty);
set => SetProperty(NameProperty, value);
}
public static readonly PropertyInfo<string> CityProperty = RegisterProperty<string>(nameof(City), RelationshipTypes.PrivateField);
[NonSerialized]
private string _city = CityProperty.DefaultValue;
public string City
{
get => GetProperty(CityProperty, _city);
set => _city = value;
}
}
}
from cslaforum.
Back to the original question, I think maybe the answer is for GraphMerger
to handle properties defined with RelationshipTypes.PrivateField
differently.
Specifically, I can change the behavior to invoke the property setter directly. This would require you implement at least a private setter.
I think this is probably the right answer.
With this change the following code works
var obj1 = DataPortal.Create<PersonEdit>("Rocky", "Eden Prairie");
var obj2 = DataPortal.Create<PersonEdit>();
new Csla.Core.GraphMerger().MergeGraph(obj2, obj1);
Console.WriteLine($"clone Name {obj2.Name}");
Console.WriteLine($"clone City {obj2.City}");
Resulting in this output
clone Name Rocky
clone City Eden Prairie
So we can see it did merge obj1
into obj2
, including the City
property.
This is with the City
property declared like this:
public static readonly PropertyInfo<string> CityProperty = RegisterProperty<string>(nameof(City), RelationshipTypes.PrivateField);
[NonSerialized]
private string _city = CityProperty.DefaultValue;
public string City
{
get => GetProperty(CityProperty, _city);
private set => _city = value;
}
from cslaforum.
@rockfordlhotka Yes, this will resolve the issue.
Thank you for also clarifying the serialization question.
from cslaforum.
Related Issues (20)
- Quick questions about Csla 5.xx HOT 2
- Rocky Lhotka and CSLA .NET AMA survey
- 2 Blazor Questions HOT 7
- HttpProxy Authentication Problem HOT 8
- Including DataPortalController in Blazor.Server HOT 4
- Add virtual to Parent HOT 1
- Blazor ViewModel additional functionality (3 questions) HOT 25
- CSLA version 5.2.0 prerelease 20042401
- Live interactive discussion about CSLA .NET May 14, 2020 HOT 6
- ASP.NET Core - iOS Specific - Unable to read beyond the end of the stream HOT 7
- CSLA version 5.2.0 prerelease 20042901
- how to convert Csla.ApplicationContext.User to SLMPrincipal class ? HOT 2
- "Data binding" for rules HOT 3
- Dapper and Csla Helper Classes HOT 3
- CSLA 5.2.0-20050802 prerelease
- Require Dependency Injection HOT 7
- Blazor Server Side. Authorization not work when deploy on Azure WebSite with SignalR HOT 2
- Async call for CSLA 5.2.0-R20050802 HOT 2
- NEW FORUM LOCATION HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cslaforum.