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)
175 T result =
default(T);
192 if (ApplicationContext.AutoCloneOnUpdate)
200 if (ApplicationContext.AutoCloneOnUpdate)
213 OnSaved(result,
null, userState);
231 public T
Save(
bool forceUpdate)
233 if (forceUpdate &&
IsNew)
294 public void BeginSave(EventHandler<SavedEventArgs> handler)
311 public async
void BeginSave(
bool forceUpdate, EventHandler<SavedEventArgs> handler,
object userState)
313 T result =
default(T);
314 Exception error =
null;
317 result = await
SaveAsync(forceUpdate, userState,
false);
319 catch (AggregateException ex)
321 if (ex.InnerExceptions.Count > 0)
322 error = ex.InnerExceptions[0];
332 OnSaved(
null, error, userState);
333 handler?.Invoke(
this,
new SavedEventArgs(result, error, userState));
371 public void BeginSave(
bool forceUpdate, EventHandler<SavedEventArgs> handler)
373 this.
BeginSave(forceUpdate, handler,
null);
391 public void BeginSave(EventHandler<SavedEventArgs> handler,
object userState)
393 this.
BeginSave(
false, handler, userState);
398 #region ISavable Members
402 OnSaved((T)newObject,
null,
null);
407 OnSaved(newObject,
null,
null);
417 return Save(forceUpdate);
429 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Design",
430 "CA1062:ValidateArgumentsOfPublicMethods")]
435 if (value.Method.IsPublic &&
436 (value.Method.DeclaringType.IsSerializable ||
437 value.Method.IsStatic))
439 System.Delegate.Combine(_serializableSavedHandlers, value);
442 System.Delegate.Combine(_nonSerializableSavedHandlers, value);
446 if (value.Method.IsPublic &&
447 (value.Method.DeclaringType.IsSerializable ||
448 value.Method.IsStatic))
449 _serializableSavedHandlers = (EventHandler<Csla.Core.SavedEventArgs>)
450 System.Delegate.Remove(_serializableSavedHandlers, value);
453 System.Delegate.Remove(_nonSerializableSavedHandlers, value);
475 [EditorBrowsable(EditorBrowsableState.Advanced)]
476 protected virtual void OnSaved(T newObject, Exception e,
object userState)
479 if (_nonSerializableSavedHandlers !=
null)
480 _nonSerializableSavedHandlers.Invoke(
this, args);
481 if (_serializableSavedHandlers !=
null)
482 _serializableSavedHandlers.Invoke(
this, args);
487 #region Register Properties/Methods
504 return Core.FieldManager.PropertyInfoManager.RegisterProperty<P>(typeof(T), info);
528 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
543 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
571 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
598 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
614 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
644 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
645 return RegisterProperty(reflectedPropertyInfo.
Name, friendlyName, defaultValue);
675 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
676 return RegisterProperty(reflectedPropertyInfo.
Name, friendlyName, defaultValue, relationship);
696 System.Reflection.
MethodInfo reflectedMethodInfo = Reflect<T>.GetMethod(methodLambdaExpression);
This is the base class from which most business objects will be derived.
void BeginSave(bool forceUpdate, EventHandler< SavedEventArgs > handler)
Starts an async operation to save the object to the database.
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.
void BeginSave(object userState)
Starts an async operation to save the object to the database.
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.
void BeginSave(EventHandler< SavedEventArgs > handler)
Starts an async operation to save the object to the database.
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 void BeginSave(bool forceUpdate, EventHandler< SavedEventArgs > handler, object userState)
Starts an async operation to save the object to the database.
void BeginSave(bool forceUpdate)
Starts an async operation to save the object to the database.
void BeginSave()
Starts an async operation to save the object to the database.
void BeginSave(EventHandler< SavedEventArgs > handler, object userState)
Saves the object to the database, forcing IsNew to false and IsDirty to True.
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() ...
This is the client-side DataPortal.
T Update(T obj)
Called by a factory method in a business class or by the UI to update an object.
async Task< T > UpdateAsync(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 object.
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.