[英]Set a string column to nullable in EF6
我有一個通過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; }
}
如您所見,我的模型中有幾個Nullable int列,但是我無法將字符串列設置為null:
public Nullable<string> AutherUserName { get; set; }
我得到這個錯誤:
為了在通用類型或方法“ System.Nullable”中將其用作參數“ T”,類型“字符串”必須為非空值類型
我正在使用MVC4
字符串是引用類型,因此已經是“可為空”。 只有值類型(例如int)可以為空,否則它們不能為null。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.