|
|
|
Forum Member
      
Group: Forum Members
Last Login: 2011-12-15 02:08:37
Posts: 35,
Visits: 260
|
|
I want to know which field is modified at updatedatabase,So I use Idirtylistservice. But I find it seems there are only changed object list,not the field list of changed object list. I think eco realy update objects to database,should only update the changed field value,not all fields value changed,is realy?
Who can tell me how to get the change list of field of one object when the object update to database by simple ways?
thanks!
|
|
|
|
|
Supreme Being
      
Group: Administrators
Last Login: 2010-11-30 12:17:13
Posts: 1 230,
Visits: 1 382
|
|
The default setting in ECO is to only update the values that has been changed, but it is also possible to "update whole object". THis is controlled by a property on the EcoSpace (bool UpdateWholeObjects).
If you have an object that has been modified and want to know what properties of that object has been modified, you need to use IStateService. Something like this:
Invoice myInvoice = ... something that returns an invoice
IObject obj = myInvoice.AsIObject();
IStateService ss = obj.ServiceProvider.GetEcoService<IStateService>();
foreach (IProperty prop in myInvoice.AsIObject().Properties)
if (ss.IsDirty(prop))
DoSomething(prop);
/Jonas Hogstrom [CapableObjects]
|
|
|
|
|
Forum Member
      
Group: Forum Members
Last Login: 2011-12-15 02:08:37
Posts: 35,
Visits: 260
|
|
|
|
|
|
Forum Guru
      
Group: Forum Members
Last Login: 2012-01-27 22:15:27
Posts: 61,
Visits: 854
|
|
We are doing something similar to this to record an audit traill of changes to objects. Is there any way to get the original value of the object using the state service, or otherwise.
Regards,
David
|
|
|
|
|
Supreme Being
      
Group: Administrators
Last Login: 2010-11-30 12:17:13
Posts: 1 230,
Visits: 1 382
|
|
In the cache (ICache interface), you can query for the fetched value of an object:
object GetFetchedValue(Locator locator, IStructuralFeature structuralFeature);
You can check if the fetched value differs from the current value using:
bool GetMemberHasFetchedValue(Locator locator, IStructuralFeature structuralFeature);
You can only get the cache interface from inside the EcoSpace-class, but you can register it as a service yourself:
public WhenImThereEcoSpace() : base()
{
this.InitializeComponent();
RegisterEcoService<Eco.Cache.ICache>(this.FrontsidePolicy.Cache);
}
/Jonas Hogstrom [CapableObjects]
|
|
|
|
|
Forum Member
      
Group: Forum Members
Last Login: 2011-12-15 02:08:37
Posts: 35,
Visits: 260
|
|
I add some code to record the change value at the method UpdateDatabase() of parecospace.cs file;But I found when submitchange at the autoform.aspx or I set the manualUpdate=false of ecodatasource ,this method updatedatabase() didn't called.
I don't know where can I trigger the updatedabase action?
Another question is how to get the old value and new value of changed field ?
thanks !
|
|
|
|
|
Supreme Being
      
Group: Administrators
Last Login: 2010-11-30 12:17:13
Posts: 1 230,
Visits: 1 382
|
|
To get the old value of the object, see my previous post (ICache interface).
It is correct that the ASP autoform doesn't call the Update method on the ecospace, it uses the services to perform the updates. You can intercept the calls to update with the following code:
public class MyPersistenceService : Eco.Persistence.ChainedPersistenceServiceBase
{
public override void UpdateDatabaseWithList<T>(IEnumerable<T> list)
{
base.UpdateDatabaseWithList<T>(list);
}
}
public MyEcoSpace() : base()
{
this.InitializeComponent();
RegisterEcoService<IPersistenceService>(new MyPersistenceService() { NextPersistenceService = Persistence });
}
In the overridden UpdateDatabaseWithList you can perform your own stuff before or after the call to the base class. The list will be a list of IObjects if I'm not mistaken.
/Jonas Hogstrom [CapableObjects]
|
|
|
|
|
Forum Member
      
Group: Forum Members
Last Login: 2011-12-15 02:08:37
Posts: 35,
Visits: 260
|
|
Some questions:
1. the first param in the method GetFetchedValue(Locator locator, IStructuralFeature structuralFeature) should how to get?
I get the id from iid.IdForObject(anobj.AsIObject()),how to translat the string id to ObjectId?
like this:ics.GetFetchedValue(ics.GetLocatorById(objid), prop.StructuralFeature),isn't right?
2.as your code,
public class MyPersistenceService : Eco.Persistence.ChainedPersistenceServiceBase
{
public override void UpdateDatabaseWithList(IEnumerable list)
{
[color=#ff0000] // where I can do some[/color]
base.UpdateDatabaseWithList(list);
}
}
In the method of UpdateDatabaseWithList,How can I get IEcoServiceProvider? I will add new object,and use IEcoServiceProvider to get all dirtyobjest lsit.
3.this line: RegisterEcoService(new MyPersistenceService() { NextPersistenceService = Persistence })
new MyPersistenceService() { NextPersistenceService = Persistence } what's means? I don't understand.
Thanks.
|
|
|
|
|
Supreme Being
      
Group: Administrators
Last Login: 2010-11-30 12:17:13
Posts: 1 230,
Visits: 1 382
|
|
A locator is an internal representation of an object. To convert from a locator to an object, you should use the ObjectRepresentationProvider that you can access from myEcoSpace.FrontSidePolicy.ObjectRepresentationProvider. You can add this as a parameter to the constructor of your PersistenceService so that you have that easily accessible in your service.
To have access to the IEcoServiceProvider in your service, just do like the suggestion above, pass it as a parameter to the constructor and keep a local reference in the service for future use.
The following syntax:
new MyPersistenceService() { NextPersistenceService = Persistence }
simply means that it will create a new instance of MyPersistenceService and set the property NextPersistenceService to the value of "Persistence" (which is the old persistenceservice that you are replacing).
/Jonas Hogstrom [CapableObjects]
|
|
|
|
|
Forum Member
      
Group: Forum Members
Last Login: 2011-12-15 02:08:37
Posts: 35,
Visits: 260
|
|
| thank you!,I have resolved.
|
|
|
|