实体框架MetadataType DefaultSettingValue

时间:2019-04-29 16:41:44

标签: entity-framework entity-framework-4

使用WebApi和VB.net使用实体框架。普通模特的TipoDatos。违约的默认担保物, utilizo MetadataType,默认中位数<UserScopedSettingAttribute(), DefaultSettingValue("999")> 默认值是默认值。 Necesito ayuda确定动机。

LA SIGUIENTE CLASE LA GENERA实体框架

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel.DataAnnotations
Partial Public Class TipoDatos
    Public Property Id As Integer
    Public Property CpoIntNND As Integer
    Public Property CpoIntNNSD As Integer
    Public Property CpoIntND As Nullable(Of Integer)
    Public Property CpoIntNSD As Nullable(Of Integer)
    Public Property CpoChrNND As String
    Public Property CpoChrNNSD As String
    Public Property CpoChrND As String
    Public Property CpoChrNSD As String
    Public Property CpoFecNND As Date
    Public Property CpoFecNNSD As Date
    Public Property CpoFecND As Nullable(Of Date)
    Public Property CpoFecNSD As Nullable(Of Date)
    Public Property CpoMioNND As Decimal
    Public Property CpoMioNNSD As Decimal
    Public Property CpoMioND As Nullable(Of Decimal)
    Public Property CpoMioNSD As Nullable(Of Decimal)
End Class

LA SIGUIENTE CLASE ES LA METADATA PARA INDICAR EL VALOR DEFAULT

Imports System
Imports System.ComponentModel.DataAnnotations
Public Class TipoDatosMetadata
    <UserScopedSettingAttribute(), DefaultSettingValue("zzz")>
    Public Property CpoChrNND As String
End Class
------------------------------------------------------------------------------
LA SIGUIENTE CLASE ES EL NEXO ENTRE LA CLASE PRINCIPAL Y LA METADATA
Imports System
Imports System.ComponentModel.DataAnnotations
<MetadataType(GetType(TipoDatosMetadata))>
Partial Public Class TipoDatos
End Class

EL CONTROLADOR CONTIENE EL POST

       ' POST: api/TipoDatos
<ResponseType(GetType(TipoDatos))>
Async Function PostTipoDatos(ByVal tipoDatos As TipoDatos) As Task(Of IHttpActionResult)
            Try

                If Not ModelState.IsValid Then
                    Return BadRequest(ModelState)
                End If

                db.TipoDatos.Add(tipoDatos)

                Await db.SaveChangesAsync()

                Return Ok(tipoDatos)
                'Return CreatedAtRoute("DefaultApi", New With {.id = tipoDatos.Id}, tipoDatos)

            Catch ex As Exception
                Return BadRequest(ex.InnerException.ToString)
            End Try
End Function

EL POST ENVIADO DESDE POSTMAN ES:

{"Id":0,
"CpoIntNNSD":1,
"CpoChrNNSD":"a         ",
"CpoFecNNSD":"2019-01-01",
"CpoMioNNSD":11.11
}

QUE RETORNA错误:无法将值NULL插入列'CpoChrNND'

0 个答案:

没有答案