Set a string column to nullable in EF6

asp.net-mvc asp.net-mvc-4 c# entity-framework

Question

I have a model that i created it bu 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; }
}

As you can see i have several Nullable int columns in my model ,But i can't set a string column to null :

public Nullable<string> AutherUserName { get; set; }

And I got this error :

The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable'

I am working with MVC4

1
13
8/17/2016 10:18:57 AM

Accepted Answer

Strings are reference types, so are already "nullable". Only value types (such as int) can be nullable as they can't otherwise be null.

29
4/5/2014 8:34:12 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow