WPF Databinding to collection/view and adding new entity

Posts   
 
    
tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 03-Nov-2009 22:40:32   

Using 2.6 DEMO, I've tried everything I can think of. Here is what I currently have going on.

Using the WPFToolkit DataGrid, I've set my ItemsSource like so:


               EntityCollection<NoiseMeasurementEntity> noise_collection = new EntityCollection<NoiseMeasurementEntity>();
               adapter.FetchEntityCollection(noise_collection, null);
               noise = new EntityView2<NoiseMeasurementEntity>(noise_collection);

               NoiseGrid.ItemsSource = noise;

I was having problems with my real entity creation code, so I made this function triggered by a Button:


      private void CreateNoise_Click(object sender, RoutedEventArgs e)
      {
         using(DataAccessAdapter adapter = new DataAccessAdapter())
         {
            NoiseMeasurementEntity nm = new NoiseMeasurementEntity();
            nm.DataFileName = "eenie";
            nm.DataFileIndex = 0;
            //set other params too
            adapter.SaveEntity(nm);
            noise.RelatedCollection.Add(nm);
         }
      }

After this returns, I do get a new row in the grid, but it only has its PK set. The rest of the fields are blank.

Requerying/Restarts show the values.

I set up another test function to tweak a value of the selected entry, and the databinding works there, the value is updated as expected.

I've tried EntityCollection.AddNew, and ((IBindingList)EntityView2).AddNew.

What am I missing?

tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 03-Nov-2009 23:38:13   

refetch! argh.

I know I read somewhere about a setting you can use that says "my database won't be changing things, I don't need to refetch, now where was that..."

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 04-Nov-2009 04:40:40   

You can mark the saved entities as fetched:

<add key="markSavedEntitiesAsFetched" value="true"/>
David Elizondo | LLBLGen Support Team
tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 04-Nov-2009 14:54:41   

There it is, thanks for helping out a novice.

I'm not a big fan of app.config in general, are there any gotchas with using EntityBase2.MarkSavedEntitiesAsFetched?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 04-Nov-2009 15:36:10   

are there any gotchas with using EntityBase2.MarkSavedEntitiesAsFetched?

None, unless you have some fields set at the database (using a trigger for example). Then these data won't appear in your entity, coz it's not fetched, while your application thinks the entity is synched with the database.

But if you don't have any field set by the databse (except the PK which gets populated back), then you're in safe position.