What is Opf3? Why is Opf3? How is Opf3? All these burning questions and issues discussed here.
 | |
| | Hello, I used the Wizard to generate my persistent objects and the ID field has a private setter: [Field("customer_id", AllowDBNull = false, Identifier = true, AutoNumber = true)] public int CustomerID { get { return _customerID; } private set { _customerID = value;
OnRowChanged("CustomerID"); } } When I attempt to instantiate the class, I get the following exception: "System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: Unable to generate a temporary class (result=1). error CS0200: Property or indexer 'ClassName.Customer.CustomerID' cannot be assigned to -- it is read only" If I remove the private designation from the setter, I no longer get the exception, however when I persist the object in the database, I get an inserted row with a new ID instead of an update.
|
 | |
| | Hi! You don't need to set the private accessor for the property. When you send the objects via webservice you need to implement the ISelfContainingObject interface into your persistent objects. The interface is found in the Chili.Opf3 namespace.
|
 | |
| | Thanks for the help Christian. I seem to still be seeing the same results even when my objects implement the ISelfContaingObject interface. I have a web service and client based on the included samples, and when I persist the object, I get a new record with a new ID, rather than an updated record. Do you have any idea what I may be doing wrong? Thanks!
Web Methods:
[WebMethod] public ObjectSet<Customer> GetCustomer(string conditions, params object[] parameters) { // Get the ObjectContext. ObjectContext context = GetObjectContext(); // Get an ObjectSet and return it. ObjectSet<Customer> os = context.GetObjectSet<Customer>(conditions, parameters); return os; }
/// <summary> /// Persist the Customer. /// </summary> /// <param name="Customer">The Customer object that is persisted.</param> [WebMethod] public bool PersistCustomer(Customer Customer) { // Get the ObjectContext. ObjectContext context = GetObjectContext();
// Start a transaction. context.StartTransaction(); try { // Persist the changes on the object. context.PersistChanges(Customer); context.Commit(); } catch { // Roll the update back. context.Rollback(); //TODO: error messaging return false; } return true; }
Customers object:
[Persistent("customers")] public class Customer : IDynamicExtensible, IObjectNotification, ISelfContainingObject, INotifyPropertyChanged, ICustomer { #region Fields
private string _name; private int _customerID;
#endregion
#region Properties
/// <summary> /// This property is mapped to the "name" field. Mandatory. /// Storage comment: . /// </summary> [Field("name", AllowDBNull = false)] public string Name { get { return _name; } set { if (value == null) throw new ArgumentNullException("value", "Value is null."); _name = value;
OnRowChanged("Name"); } }
/// <summary> /// Returns the identifier of the persistent object. Don't set it manually! /// </summary> [Field("customer_id", AllowDBNull = false, Identifier = true, AutoNumber = true)] public int CustomerID { get { return _customerID; } set { _customerID = value;
OnRowChanged("CustomerID"); } }
#endregion ....
client code:
ObjectSet<foo.Customer> os = new ObjectSet<foo.Customer>(service.GetCustomer("CustomerID = {0}", new object[] { args[1] }));
// Get the first object that has been returned and change a property. spoink.Customer customer = os[0]; Console.WriteLine("changing name " + customer.Name + " to " + args[2]); customer.Name = args[2]; // Try to save the changed object. if (service.PersistCustomer(customer)) Console.WriteLine("Sucessfully saved!"); else Console.WriteLine("Error while saving!");
|
 | |
| | Hi bc. From your code snippets I don't see how and where you implemented the ISelfContainingObject interface.
|
 | |
| | Oops, here is the snippet. Also from Customer class:
#region ISelfContainingObject Members
private ObjectInfo _objectInfo = null;
/// <summary> /// Returns the <see cref="Opf3.ObjectInfo">ObjectInfo</see> object that contains all /// information required to make the persistent object /// <see cref="Opf3.ObjectContext">independent from any ObjectContext</see>. /// </summary> /// <value> /// <see cref="Opf3.ObjectInfo">ObjectInfo</see> object that holds the status /// information of the persistent object. /// </value> ObjectInfo ISelfContainingObject.ObjectInfo { get { return _objectInfo; } set { _objectInfo = value; } }
#endregion
Thanks again!
|
 | |
| | Try to implement the interface normally. So that the property is visible without casting to the interface :)
Thanks, Christian
|
 | |
| | Thanks Christian, I am slightly confused as to what you mean by implementing the interface normally. I am using code that has been generated by the Opf3 Wizard and as you can see from the customers class above and repeated below, I have the ISelfContainingObject interface listed in the class definition. This appears to be identical to any of the samples I have found in the documentation. Is there something else that I am missing? Thanks, -Brian
/// <summary> /// Persistent object for the "customers" table. /// </summary> [Serializable] [Persistent("customers")] public class Customer : IDynamicExtensible, IObjectNotification, ISelfContainingObject, INotifyPropertyChanged, ICustomer
|
 | |
| | In your implementation the interface is stated again in the property:
ObjectInfo ISelfContainingObject.ObjectInfo Try to change that line to
public ObjectInfo ObjectInfo -Christian
|
 | |
| | Hi Christian, When I change that line according to your suggestion, a call to any of the webmethods in the webservice results in the following exception (wrapped in a soapException):
System.NotSupportedException: Cannot serialize member Chili.0pf3.ObjectInfo.ConcurrencyData of type System.ICloneable because it is an interface.
Does this provide any clue as to what my issue might be? Thanks, -Brian
|
 | |
| | Hi Christian, The WebService sample which ships with Opf3 has the interface defined as follows and is generating the same exception for me. Can you provide any insight into what the issue may be?
#region ISelfContainingObject Members
/// <summary> /// Implemented because of the remoting sample. See the documentation of the /// ISelfContainingObject interface. /// </summary> public ObjectInfo ObjectInfo { get { return _objectInfo; } set { _objectInfo = value; } }
#endregion
Thanks, -Brian
|
 | |
| | Hi. Please send me a mail... I fixed the issue :)
-Christian
|