1
I got the field descrPapel
of the kind string
and would like that field to be created as nullable
, that is, to accept null
when I was gonna do some Insert/update in records of this type of entity.
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Modelo.Classes.Banco
{
public class Papeis
{
[Key]
public Int32 idpapel { get; set; }
[Required, MaxLength(100)]
public string nomePapel { get; set; }
[Required,MaxLength(200)]
public string descrPapel { get; set; }
public DateTime dtInclusao { get; set; }
public virtual ICollection<PapeisUsuario> PapeisUsuario { get; set; }
}
}
The form the field is created to not accept values null
to that field [descrPapel] [nvarchar](200) NOT NULL,
;
See how it was created by the Entity Framework:
CREATE TABLE [dbo].[Papeis](
[idpapel] [int] IDENTITY(1,1) NOT NULL,
[nomePapel] [nvarchar](100) NOT NULL,
[descrPapel] [nvarchar](200) NOT NULL,
[dtInclusao] [datetime] NOT NULL,
CONSTRAINT [PK_dbo.Papeis] PRIMARY KEY CLUSTERED
(
[idpapel] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
I needed this field to be created as [descrPapel] [nvarchar](200) NULL,
, there is some way?
Using waste water??
– Jéf Bueno
@jbueno This, or Dataannotations, something that set as null in the database.
– Marco Souza
I didn’t understand the
[Required]
may be null.– Leonel Sanches da Silva