gpt4 book ai didi

c# - ASP.NET MVC4 + Razor on Mono + EF 6 DateTime 崩溃

转载 作者:行者123 更新时间:2023-11-30 12:45:12 25 4
gpt4 key购买 nike

我正在尝试使用 Mono 运行应用程序。它在 IIS 上运行良好,但我希望它在 Mono 上运行。但它总是把这个扔给我:

The 'CreateDate' property on 'Article' could not be set to a 'System.String' value. You must set this property to a non-null value of type 'System.DateTime'.

事实是抛出的地方是这样的:

public Article[] Select(int number)
{
return DbContextProvider.Current.Set<Article>()
.OrderByDescending(n => n.CreateDate)
.Take(number)
.ToArray();
}

System.String 没有任何用法。实际上,唯一将它转换为字符串的地方就在这里:

@using BaseSite.Extensions.DateTimeExtensions
@model Classic.Views.Home.Articles.ArticleViewModel

<div class="article-wrapper">
<div class="article-title">
@Html.ActionLink(Model.Title, "Index", "Articles", new RouteValueDictionary{{"articleId", Model.ArticleId}}, null)
</div>
@Html.Raw(Model.Text)
<div class="article-data date">
@Html.ActionLink(Model.UserId, "Index", "Profile", new RouteValueDictionary{{"userId", Model.UserId}}, null),
@Model.CreateDate.Format(true)
</div>
</div>

但错误是在那之前抛出的。而且,它在 IIS 上工作,只有在 Mono 上才有这样一个奇怪的错误。

数据库表布局为:

CREATE TABLE [dbo].[Articles](
[ArticleId] [uniqueidentifier] NOT NULL,
[UserId] [nvarchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[CreateDate] [datetime2](7) NOT NULL,
[Title] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Text] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
PRIMARY KEY CLUSTERED
(
[ArticleId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

映射类:

using System;

namespace BusinessObjects.Articles
{
public class Article
{
public Guid ArticleId { get; set; }
public string UserId { get; set; }
public DateTime CreateDate { get; set; }

public string Title { get; set; }
public string Text { get; set; }
}
}

using System.Data.Entity;

namespace BusinessObjects.Articles
{
public class ArticleMapper : IDbMapper
{
public void Map(DbModelBuilder modelBuilder)
{
var entity = modelBuilder.Entity<Article>();

entity.HasKey(n => n.ArticleId);
entity.Property(n => n.ArticleId).IsRequired();

entity.Property(n => n.UserId).IsRequired().HasMaxLength(30);
entity.Property(n => n.Title).IsRequired().HasMaxLength(50);
entity.Property(n => n.Text).IsRequired().IsMaxLength();
}
}
}

是的。我还有其他带有 DateTime 的表,它们都会出现该错误。它们都在 IIS (MS Stack) 上正常运行,它只在 Mono + xsp4 上有错误。谁能提供任何帮助?我迷失在这种怪异之中。

PS:我尝试了几乎所有的单声道版本,现在我在 Mono git master 3.8.1 (master/38c3874),3.6、3.2.8 等也是如此

最佳答案

正如 Alexander Köplinger 所提到的,似乎是 Mono 中“datetime2”的错误。通过从 MsSql 迁移到 PostgreSql 来修复 - 它在计划中。

关于c# - ASP.NET MVC4 + Razor on Mono + EF 6 DateTime 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25577219/

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