Note that there are some explanatory texts on larger screens.

plurals
  1. POSL EF - Trouble adding new record via Toolkit DataForm
    primarykey
    data
    text
    <p>Hi I'm hoping you can help me figure out why I can't add new items via my dataform.</p> <p>In my dataform I have defined an <em>Edit</em> and <em>NewItemTemplate</em>. I am showing the proper command buttons and the '+' add button shows up on my form. However, it's always grayed out and will not let me add a new item. </p> <p>I'm binding my data to the selected item in a DataGrid beside the DataForm. I'm able to update existing data, i.e. rename the item. But can't add new ones. The binded data is being loaded from EF context when the control is loaded. </p> <p><strong>I'm wondering if I need to describe my own Country class; I figure EF should be able to handle the inserts.</strong></p> <p>It seems like I'm missing something very fundamental. Any ideas/resources would be helpful. Thank you. </p> <p><em>Code as follows</em> My XAML for the DataForm:</p> <pre><code>&lt;dataFormToolkit:DataForm x:Name="dfCountry" CurrentItem="{Binding SelectedItem, ElementName=dgCountry, Mode=TwoWay}" CommitButtonContent="Save" CancelButtonContent="Cancel" AutoEdit="False" ItemsSource="{Binding Mode=OneWay}" AutoCommit="True" LabelPosition="Top" CommandButtonsVisibility="Edit, Add, Commit, Cancel, Delete" BeginningEdit="dfCountry_BeginningEdit" EditEnded="dfCountry_EditEnded" DeletingItem="dfCountry_DeletingItem" AddingNewItem="dfCountry_AddingNewItem"&gt; &lt;tk:DataForm.EditTemplate&gt; &lt;DataTemplate&gt; &lt;tk:DataField Label="Country"&gt; &lt;TextBox Text="{Binding Path=Name, Mode=TwoWay}" HorizontalAlignment="Stretch" VerticalAlignment="Top" /&gt; &lt;/tk:DataField&gt; &lt;/DataTemplate&gt; &lt;/tk:DataForm.EditTemplate&gt; &lt;tk:DataForm.NewItemTemplate&gt; &lt;DataTemplate &gt; &lt;tk:DataField Label="Country" &gt; &lt;TextBox Text="{Binding Path=CountryName, Mode=TwoWay, ValidatesOnDataErrors=True,ValidatesOnNotifyDataErrors=True}" HorizontalAlignment="Stretch" VerticalAlignment="Top" /&gt; &lt;/tk:DataField&gt; &lt;/DataTemplate&gt; &lt;/tk:DataForm.NewItemTemplate&gt; &lt;/dataFormToolkit:DataForm&gt; </code></pre> <p>My procedure to load data in the code behind. It is called when the control is instantiated.</p> <pre><code>private void LoadData() { EntityQuery&lt;Country&gt; qry = ctx.GetCountriesQuery(); LoadOperation&lt;Country&gt; loadOp = ctx.Load(qry); loadOp.Completed += new EventHandler(loadOp_Completed); } void loadOp_Completed(object sender, EventArgs e) { LoadOperation&lt;Country&gt; CountryDataLoadResult = (LoadOperation&lt;Country&gt;) sender; dgCountry.ItemsSource = CountryDataLoadResult.Entities; } </code></pre> <p>The Country model is declared in my metadata class.</p> <pre><code> [MetadataTypeAttribute(typeof(Country.CountryMetadata))] public partial class Country { internal sealed class CountryMetadata { private CountryMetadata(){} public int CountryID { get; set; } public Nullable&lt;int&gt; CreatedBy { get; set; } public Nullable&lt;DateTime&gt; CreatedDate { get; set; } public Nullable&lt;bool&gt; FlagDeleted { get; set; } public Nullable&lt;int&gt; ModifiedBy { get; set; } public Nullable&lt;DateTime&gt; ModifiedDate { get; set; } public string Name { get; set; } public EntityCollection&lt;Province&gt; Provinces { get; set; } } } </code></pre> <p>In my service class I have:</p> <pre><code>public IQueryable&lt;Country&gt; GetCountries() public void InsertCountry(Country country) public void UpdateCountry(Country currentCountry) public void DeleteCountry(Country country) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload