Ho un modello che ho creato è bu EF6:impostare una colonna stringa da annullabile in EF6
public partial class Comment
{
[DisplayName("شناسه نظر")]
public int Id { get; set; }
[Required(ErrorMessage = "متن نظر را وارد کنید")]
[DisplayName("متن نظر")]
public string CommentText { get; set; }
[DisplayName("تعداد پسندیدن ")]
public long LikeCount { get; set; }
[DisplayName("تعداد نپسندیدن")]
public long DisLikeCount { get; set; }
[DisplayName("تاریخ انتشار ")]
public System.DateTime PublishDate { get; set; }
[DisplayName("وضعیت نمایش ")]
public string Visible { get; set; }
[DisplayName("نام کاربری ")]
public Nullable<string> AutherUserName { get; set; }
[DisplayName("شناسه نظراصلی")]
public Nullable<int> CommentFKId { get; set; }
[DisplayName("شناسه کاربر")]
public Nullable<int> StudentId { get; set; }
[DisplayName("شناسه محتوا ")]
public Nullable<int> ContentId { get; set; }
public virtual Comment Comments { get; set; }
public virtual Comment Comment1 { get; set; }
public virtual Student Student { get; set; }
public virtual Content Content { get; set; }
}
Come potete vedere ho diverse Nullable colonne int nel mio modello, ma non posso impostare una colonna stringa nulla:
public Nullable<string> AutherUserName { get; set; }
E ho ottenuto questo errore:
Il tipo 'string' deve essere un non tipo di valore -nullable Per utilizzare come parametro 'T' nel tipo generico o metodo 'System.Nullable'
sto lavorando con MVC4
Possibile duplicato di http://stackoverflow.com/questions/9236468/the-type-string-must-be-a-non-nullable-type-in-order-to-use-it-as-parameter- t –
Se si desidera avere un valore null nella stringa anche se il proprio ui fornisce uno spazio vuoto, è possibile farlo nel setter della proprietà. –