Problem:
When adding new item into EntityCollectionView raised the required validation for string fields, but for my purpose we should show it after validation on server side.
Actual behavior:
Here is code from metadata file:
[MetadataTypeAttribute(typeof(SomeEntityMetadata))]
public partial class SomeEntity
{
    [EntityName]
    internal sealed class SomeEntityMetadata
    {
        private SomeEntityMetadata()
        {
        }
        public long Id { get; set; }
        [EntityName(Name = "Name", OrderIndex = 2)]
        public string Name { get; set; }
        [EntityName(Name = "Data Type", OrderIndex = 1)]
        public string Type { get; set; }
    }
}
And a collection of this items binded to DataGrid in xaml:
<navigation:DataGridTemplateColumn CanUserReorder="True"
                                   CanUserSort="True"
                                   Header="Name"
                                   SortMemberPath="Name">
    <navigation:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBlock VerticalAlignment="Center" Text="{Binding Name}"/>
        </DataTemplate>
    </navigation:DataGridTemplateColumn.CellTemplate>
    <navigation:DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <TextBox Text="{Binding Name, Mode=TwoWay}" Height="Auto"/>
        </DataTemplate>
    </navigation:DataGridTemplateColumn.CellEditingTemplate>
</navigation:DataGridTemplateColumn>
<navigation:DataGridTemplateColumn CanUserFilter="True"
                                         CanUserSort="True"
                                         Header="Type"
                                         SortMemberPath="Type">
    <navigation:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBlock VerticalAlignment="Center" Text="{Binding Type}" />
        </DataTemplate>
    </navigation:DataGridTemplateColumn.CellTemplate>
    <navigation:DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <ComboBox ItemsSource="{Binding DataTypes, Source={StaticResource entityViewModel}}" SelectedItem="{Binding Type, Mode=TwoWay}/>
        </DataTemplate>
    </navigation:DataGridTemplateColumn.CellEditingTemplate>
</navigation:DataGridTemplateColumn>
As you see there  is no [Required] attributes for fields, but when inserting new item with Name and Type fields set to String.Empty the errors "Name field is required" and  "Type field is required" appears.
Needed behavior:
Skip required validation and throw ValidationException from server when Name or Type fields are empty.
NOTE: Silverlight, EF, WCF RIA, MVVM.
For this you can set
 [Required(AllowEmptyStrings=true)]
On properties you want to pass through.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With