How to work with DataSetFields


In my view I have a DataSet for Entity Contact that I have used SetSourceCursor

There is a this association with another entity from this Entity Contact:

    [ManyValuedAssociation([], CascadeTypeAll)]
    [ForeignJoinColumn('IDMEIOSCONTATO', [TColumnProp.Required])]
    FMeiosContato: Proxy<TList<TEntityMeiosContato>>;

    property    MeiosContato: TList<TEntityMeiosContato> read GetMeiosContato;

Then I have added another DataSet on my view to connect the livebinding to a TListView using the TDataSetField:

DataSetMeiosContato.DataSetField := DataSetContact.FieldByName('MeiosContato') as TDataSetField;

Everything shows up just fine. I have all the "MeiosContato" that are related to the Contact in that DataSet.

Now I need to Add a New MeiosContato.

I wanted to do that not based on the DataSet. I have Created a New TEntityMeiosContato

I have added the values.

And Now i need to ADD this new Entity object to the List of the current "record" of DataSet Contact.

Here is my problem. After I gave the Cursor to the DataSet I dont have it anymore...

I have the TEntityMeiosContato just created and need to add it to the Current record, and expect that the Dataset MeiosContato get refreshed with the new value.

Should I use the Self from the Contact to get the TEntityContact and then:

TEntityContact.MeiosContato.Add(TEntityMeiosContato)  ?

OR 

Should I add it to the DataSet MeiosContato (that is a Tdatasetfield from the Contact dataset) ? But how?

I dont want to use the standard DataSet controls, I want to use object creation. I am only using DataSet for the livebinding

OR

Can I just retrieve the current Contact in another object using Manar.Find<TEntityContact>(ContactID) and then add my TEntityMeiosContato to the MeiosContato property and MAnager.Save?

How can get is refreshed on the current Dataset? Actually I need only the MeiosContato DataSet refreshed since the Contact DataSet could be in edit mode !!!!!

Sorry I am lost here.



Is the dataset associated with a manager? You say that you only use the dataset for livebinding, so my guess would be that the dataset objects are dettached from a manager? However, you say that you are using SetSourceCursor, which implies that the manager is still alive while the cursor is being used thus the objects are being managed?


Well, in general, you should add the object from the dataset, if you want it to be completely in sync with the objects that the dataset represents. There is no such method that "adds an object" to the dataset. 
But since you don't want to use the dataset, I guess the best (maybe only) approach is that you add the MeiosContato object to the Current of your parent dataset, then just refresh the MeiosContato dataset. Your last option also confused me. Do you want just add the object to the dataset for visual purposes, or do you want to update the database?

About the manager:


My view has one main Dataset that in this case represents my TEntityContact 

This dataset gets the available Contacts from MAnager.FindAll<TEntityContact> from the mode attached

And receives the Manager also

THe other DataSet on the View is based on TDataSetFields from the Main DataSet, so I have all the Relationships

But I need to add new "records" to these relationships. Not changing the main dataset, That is probably in Edit mode.

So I need to add a record to one of the TDataSetFields that were defined as DataSet.

I dont want to use the DataSet methods and FieldByName stuff. I want to create an Object Entity and add it to the relationship of my main Dataset.

I gave the example of MeiosContato DataSet. That is a TList<TEntityMeiosContato> in TEntityContact.

So I need to Add this object to the TList. And it gets saved. 

EVerything using the same manager here. I need that the Related DataSet get refreshed, but not the main dataset, that I said is in Edit mode certanly. The others are in Browse mode.

How?

My entire structure is based on objects, The TAureliusDataSet is only the tip of the iceberg. So while presenting data how to add objects? And specially how to get from the current record the context to insert an entity object. 


I am fine if I could persist the object to the database and then force a refresh, BUT this refresh only can act only on the relationships. Eventually I am using wrong based on the TDataSetField, but I dont know how to master-detail other way.

Add the newly created object using


MainDataset.Current<TEntityContact>.MeiosContato.Add(NewMeiosContato);

then call DatasetMeiosContato.Refresh;
It will probably work because DatasetContato doesn't keep any buffer info for dataset fields, so you could update the object directly without dealing with the dataset. But this is an exception and somehow you got "lucky" because you can do that. Usually you will be limited by the TDataset mechanism - how would you want the dataset to be updated without using their own dataset mechanisms? The dataset doesn't "know" about Aurelius objects, it's an abstract layer, so unless you refresh the dataset (or the record), you can't update the dataset content without using their own methods.

I will try that. Apparently is what I need... .I have many relations like that MeiosContato.


I am problem lost here in one thing, I do understand that DAtaSet is just an abstraction Layer. I dont wanted to deal with it for object insertion.  

No problem having to call REFRESH. After inserting the (NewMeiosContato) I know based on the context that I need to refresh this dataset.

However, I am not sure about the mechanics behind it. 

Shoud I keep the CursorCriteria that I gave to the DataSet, and use it to create new objects like this?

If that is correct, how would I know the current position of the Cursor? Which is the current object/record that is being edited, so I can add directly to the entity properties TList<> each new object created. and after call the refresh on the DataSet.

Basically, I need to be deal with one step before the dataset. But I need to be syncronized with it. I need to know the context of the user, which "record" is being edited. etc.

but, again, your direction solve my problem, but I am dealing with the Dataset, so my post above is what I really need. What is the step right before the DataSet that I should work with? 


Working with ICriteriaCursor/TCriteria? which one? 

The Main DataSet will not get refresh ever, all this situation is based on the relationship objects/dataset

Maybe I should quickly explain the concept, then you can define what's best for you.

TAureliusDataset is just a TDataset that instead of retrieving data from a database server, it retrieves data from objects. The objects (in memory) are the source of data for TAureliusDataset. Forget about the manager or saving/loading objects to the database. TAureliusDataset just looks for objects in memory. Thus, whatever way you provide data to it (using TList<>, or TCriteria, or ICriteriaCursor), the only difference it makes is how the dataset is going to retrieve the next record, when needed. Other than this, any source you use works the same way: the dataset is editing objects in memory, either in the TList<> you provided, or in an internal list it keeps when retrieving records using cursors. The current record is just the current object being edited. You can use Locate method, or bookmarks, for example, to search for a record associated with an object. When you Post a record, the dataset justs updates the object. 

I guess maybe you can go on with this info? Note that the behavior is the same as regular dataset: if you run an SQL and open it with a dataset, if another user adds a record to the database, there is no way the dataset can "see" that record without calling a Refresh. Here is the same: if you add an object to the list, only way this object can be visible in the dataset is by doing a Refresh. Unless, of course, if you insert a record in the dataset and let the dataset create the object for you.