9using System.ComponentModel;
10using System.Linq.Expressions;
11using System.Reflection;
15using System.Threading.Tasks;
40 #region Object ID Value
53 #region System.Object Overrides
64 return base.ToString();
125 return SaveAsync(
false,
null,
true).Result;
127 catch (AggregateException ex)
129 if (ex.InnerExceptions.Count > 0)
130 throw ex.InnerExceptions[0];
153 return await
SaveAsync(forceUpdate,
null,
false);
165 protected async
virtual Task<T>
SaveAsync(
bool forceUpdate,
object userState,
bool isSync)
167 if (forceUpdate &&
IsNew)
189 result = dp.
Update((T)
this);
197 result = await dp.UpdateAsync((T)
this);
214 OnSaved(result,
null, userState);
232 public T
Save(
bool forceUpdate)
234 if (forceUpdate &&
IsNew)
271 #region ISavable Members
275 OnSaved((T)newObject,
null,
null);
280 OnSaved(newObject,
null,
null);
290 return Save(forceUpdate);
302 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Design",
303 "CA1062:ValidateArgumentsOfPublicMethods")]
308 if (value.Method.IsPublic &&
309 (value.Method.DeclaringType.IsSerializable ||
310 value.Method.IsStatic))
312 System.Delegate.Combine(_serializableSavedHandlers, value);
315 System.Delegate.Combine(_nonSerializableSavedHandlers, value);
319 if (value.Method.IsPublic &&
320 (value.Method.DeclaringType.IsSerializable ||
321 value.Method.IsStatic))
322 _serializableSavedHandlers = (EventHandler<Csla.Core.SavedEventArgs>)
323 System.Delegate.Remove(_serializableSavedHandlers, value);
326 System.Delegate.Remove(_nonSerializableSavedHandlers, value);
348 [EditorBrowsable(EditorBrowsableState.Advanced)]
349 protected virtual void OnSaved(T newObject, Exception e,
object userState)
352 if (_nonSerializableSavedHandlers !=
null)
353 _nonSerializableSavedHandlers.Invoke(
this, args);
354 if (_serializableSavedHandlers !=
null)
355 _serializableSavedHandlers.Invoke(
this, args);
360 #region Register Properties/Methods
377 return Core.FieldManager.PropertyInfoManager.RegisterProperty<P>(typeof(T), info);
401 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
428 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
455 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
484 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
485 return RegisterProperty(reflectedPropertyInfo.
Name, friendlyName, defaultValue);
515 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
516 return RegisterProperty(reflectedPropertyInfo.
Name, friendlyName, defaultValue, relationship);
536 System.Reflection.
MethodInfo reflectedMethodInfo = Reflect<T>.GetMethod(methodLambdaExpression);
Provides consistent context information between the client and server DataPortal objects.
static bool AutoCloneOnUpdate
Gets a value indicating whether objects should be automatically cloned by the data portal Update() me...
object CreateInstanceDI(Type objectType, params object[] parameters)
Creates an object using 'Activator.CreateInstance' using service provider (if one is available) to po...
This is the base class from which most business objects will be derived.
T Save(bool forceUpdate)
Saves the object to the database, forcing IsNew to false and IsDirty to True.
async Task< T > SaveAsync(bool forceUpdate)
Saves the object to the database.
static MethodInfo RegisterMethod(string methodName)
Registers a method for use in Authorization.
EventHandler< Csla.Core.SavedEventArgs > Saved
Event raised when an object has been saved.
static PropertyInfo< P > RegisterProperty< P >(PropertyInfo< P > info)
Indicates that the specified property belongs to the business object type.
static MethodInfo RegisterMethod(Expression< Action< T > > methodLambdaExpression)
Registers a method for use in Authorization.
override string ToString()
Returns a text representation of this object by returning the GetIdValue value in text form.
virtual object GetIdValue()
Override this method to return a unique identifying value for this object.
virtual async Task< T > SaveAsync(bool forceUpdate, object userState, bool isSync)
Saves the object to the database.
T Save()
Saves the object to the database.
T Clone()
Creates a clone of the object.
async Task< T > SaveAsync()
Saves the object to the database.
async Task SaveAndMergeAsync(bool forceUpdate)
Saves the object to the database, merging any resulting updates into the existing object graph.
virtual void OnSaved(T newObject, Exception e, object userState)
Raises the Saved event, indicating that the object has been saved, and providing a reference to the n...
async Task SaveAndMergeAsync()
Saves the object to the database, merging any resulting updates into the existing object graph.
virtual bool IsBusy
Gets a value indicating if this object or its child objects are busy.
virtual bool IsValid
Returns true if the object and its child objects are currently valid, false if the object or any of i...
bool IsDeleted
Returns true if this object is marked for deletion.
virtual object GetClone()
Creates a clone of the object.
bool IsNew
Returns true if this is a new object, false if it is a pre-existing object.
virtual void MarkOld()
Marks the object as being an old (not new) object.
void MarkDirty()
Marks an object as being dirty, or changed.
bool IsChild
Returns true if this is a child (non-root) object.
virtual bool IsDirty
Returns true if this object's data, or any of its fields or child objects data, has been changed.
void MarkIdle()
Mark the object as not busy (it is not running an async operation).
void MarkBusy()
Mark the object as busy (it is running an async operation).
Implements behavior to merge one object graph into a clone of itself (typically post-serialization).
void MergeGraph(IEditableBusinessObject target, IEditableBusinessObject source)
Merges state from source graph into target graph.
Event arguments containing a reference to the new object that was returned as a result of the Save() ...
Client side data portal used for making asynchronous data portal calls in .NET.
T Update(T obj)
Called by a factory method in a business class or by the UI to update an object.
Maintains metadata about a method.
MethodInfo(string name)
Creates an instance of the type.
A strongly-typed resource class, for looking up localized strings, etc.
static string BusyObjectsMayNotBeSaved
Looks up a localized string similar to Objects that are marked busy may not be saved.
static string NoSaveEditingException
Looks up a localized string similar to Object is still being edited and can not be saved.
static string NoSaveInvalidException
Looks up a localized string similar to Object is not valid and can not be saved.
static string NoSaveChildException
Looks up a localized string similar to Can not directly save a child object.
Maintains metadata about a property.
string Name
Gets the property name value.
Specifies that the object can save itself.
void SaveComplete(object newObject)
INTERNAL CSLA .NET USE ONLY.
object Save()
Saves the object to the database.
Task< object > SaveAsync()
Saves the object to the database.
int EditLevel
Gets the current edit level of the object.
Consolidated interface of public elements from the BusinessBase type.
RelationshipTypes
List of valid relationship types between a parent object and another object through a managed propert...
@ Serializable
Prevents updating or inserting until the transaction is complete.