locked
Problem in insert into WCF RIA table with default value of column 2 spaces RRS feed

  • Question

  • Hello, I am inserting a record in a SQL table that has several fields. All of them are mandatory, meaning that NOT accept NULL, default and has defined several blanks. for example, the seller has two field blanks.

    The problem is that when doing the insert is this ...

    Dim nuevoalbaran As c_albvenItem = Me.DataWorkspace.FacturacionData.c_albven.AddNew()
                'le metemos la info
                nuevoalbaran.EMPRESA = Me.Incidencias.CodigoEmpresa.EmpresaID.CODIGO
                nuevoalbaran.LETRA = Me.Incidencias.CodigoEmpresa.SerieDeFacturaciónEurowin
                nuevoalbaran.NUMERO = SIGUIENTEALBARAN.PadLeft(10) 
                nuevoalbaran.CLIENTE = Me.Incidencias.Cliente.CODIGO
                nuevoalbaran.FECHA = Date.Today.Date
                nuevoalbaran.ALMACEN = "01"
                nuevoalbaran.FPAG = FORMAPAGO
                nuevoalbaran.IMPORTE = IMPORTEALBARAN
                nuevoalbaran.IMPDIVISA = IMPORTEALBARAN
                nuevoalbaran.VENDEDOR = ""
                nuevoalbaran.PEDIDO = nuevoalbaran.PEDIDO

    ..............

    as you see the Salesperson field I put White or empty or "" but LS error I jump the Salesperson field is mandatory, I mean, as if it were happening any security.

    How I can make this work for me?

    Wednesday, September 25, 2013 9:30 PM

Answers

All replies

  • See:

    http://msdn.microsoft.com/en-us/library/vstudio/gg589479.aspx

    public class Customer
    {
      [Required]
      [StringLength(50)]
      public string LastName { get; set; }
    }
    

    RequiredAttribute

    In LightSwitch, this property affects only fields that have a string type. If you set the AllowEmptyStrings property of this attribute to False, in LightSwitch, the Is Required property of the field is set to True.


    Unleash the Power - Get the LightSwitch HTML Client book

    http://LightSwitchHelpWebsite.com

    Wednesday, September 25, 2013 11:04 PM
  • Actually, can you show the code for your WCF RIA Service method that handles the insert? The error may come from the underlying table that you are trying to insert into so my earlier comment does not apply.


    Unleash the Power - Get the LightSwitch HTML Client book

    http://LightSwitchHelpWebsite.com

    Wednesday, September 25, 2013 11:07 PM
  • Hi Michel, thanks for your response.

    this is part of code from the ria service, where i need to put the required?

    File Metadata:

    'El MetadataTypeAttribute identifica a c_albvenMetadata como la clase
    ' que contiene metadatos adicionales para la class c_albven.
    <MetadataTypeAttribute(GetType(c_albven.c_albvenMetadata))>  _
    Partial Public Class c_albven
        
        'Esta clase permite adjuntar atributos personalizados a properties
        ' de la clase c_albven.
        '
        'Por ejemplo, lo siguiente marca la property Xyz como una
        ' property requerida y especifica el formato de los valores válidos:
        '    <Required()>
        '    <RegularExpression("[A-Z][A-Za-z0-9]*")>
        '    <StringLength(32)>
        '    Public Property Xyz As String
        Friend NotInheritable Class c_albvenMetadata
            
            'No se van a crear instancias de las clases de metadatos.
            Private Sub New()
                MyBase.New
            End Sub
            
            Public Property ALMACEN As String
            
            Public Property ASI As String
            
            Public Property NUMERO As String
            
            Public Property OBRA As String
            
            Public Property OBSERVACIO As String
            
            Public Property OPERARIO As String
            
            Public Property PEDIDO As String
            
            Public Property PESO As Decimal
            
            Public Property PRESUP As String
            
            Public Property PRONTO As Decimal
            
            Public Property PUNTOS As Decimal
            
            Public Property RECEQUIV As Boolean
            
            Public Property RUTA As String
            
            Public Property SEND_FRA As Boolean
            
            Public Property STOCK_COEF As Decimal
            
            Public Property TAG As Boolean
            
            Public Property TPCRETNOFI As Decimal
            
            Public Property TRASPASADO As Boolean
            
            Public Property USUARIO As String
            
            Public Property VENDEDOR As String
            
            Public Property VISTA As Nullable(Of Boolean)
        End Class
    End Class

    Thursday, September 26, 2013 7:09 PM
  • That is the class definition. Do you have the actual code that performs the insert?

    It would be a method with the words "insert" or "update" in the name.


    Unleash the Power - Get the LightSwitch HTML Client book

    http://LightSwitchHelpWebsite.com

    Thursday, September 26, 2013 7:30 PM
  • And this is code from property vendedor...

     <EdmScalarPropertyAttribute(EntityKeyProperty:=False, IsNullable:=False)>
        <DataMemberAttribute()>
        Public Property VENDEDOR() As Global.System.String
            Get
                Return _VENDEDOR
            End Get
            Set(value As Global.System.String)
                OnVENDEDORChanging(value)
                ReportPropertyChanging("VENDEDOR")
                _VENDEDOR = StructuralObject.SetValidValue(value, False)
                ReportPropertyChanged("VENDEDOR")
                OnVENDEDORChanged()
            End Set
        End Property
     
        Private _VENDEDOR As Global.System.String = "  "
        Private Partial Sub OnVENDEDORChanging(value As Global.System.String)
        End Sub
     
        Private Partial Sub OnVENDEDORChanged()
        End Sub

    Thursday, September 26, 2013 7:31 PM
  • Ok it looks like you have a Entity Framework Data model inside your WCF RIA Service (rather than just connecting to the one that LightSwitch uses). So my only guess is that if you open up that .edmx file you will see that  AllowEmptyStrings is False

    Unleash the Power - Get the LightSwitch HTML Client book

    http://LightSwitchHelpWebsite.com

    Thursday, September 26, 2013 7:38 PM
  • on file edmx there are no reference to AllowEmptyStrings

    :(

    Thursday, September 26, 2013 9:17 PM
  • ok, this works!

    <Required(AllowEmptyStrings:=True)>         <StringLength(12)>         PublicProperty PEDIDO AsString

    thanks!

      

    • Marked as answer by Ivan Martinez Thursday, September 26, 2013 9:39 PM
    Thursday, September 26, 2013 9:38 PM