gpt4 book ai didi

c# - 在 EF6 中将字符串列设置为可为空

转载 作者:可可西里 更新时间:2023-11-01 08:03:28 25 4
gpt4 key购买 nike

我有一个使用 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 列,但我无法将字符串列设置为空:

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

我得到了这个错误:

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'

我正在使用 MVC4

最佳答案

字符串是引用类型,因此已经是“可为空的”。只有值类型(如 int)可以为 null,否则它们不能为 null。

关于c# - 在 EF6 中将字符串列设置为可为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22886405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com