I'm starting out with db4o in .NET 4.0. Should I be using fields or properties for persistent objects?
I understand that to use the [Indexed]
attribute for unique IDs, I need to use a field. How do I implement the corresponding ID property without duplic开发者_运维知识库ating data in my database?
Use regular properties, like you would do with any other object. Keep your fields private and access them via properties and methods. That makes it more flexible, for example to rename a property.
db4o always stores field values and ignores properties. Thats why you have to add the index-attribute on a field. Also configuration-stuff always refers to the field. When you add a property db4o will just store the underlying field.
The only thing you might want to consider if you want to use auto-properties. C# auto-properties are backed by a compiler-generated field. This field-name will be very ugly. Therefore you probably want to use regular properties with a regular field.
Note: For Silverlight you need to use public fields, because db4o cannot access private fields via reflection.
精彩评论