c# – ASP.NET MVC4 Razor on Mono EF 6 DateTime崩溃
发布时间:2020-12-15 22:07:23 所属栏目:百科 来源:网络整理
导读:我正在尝试使用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
我正在尝试使用Mono运行应用程序.它在IIS上运行正常,但我希望它在Mono上运行.但它总是把它扔给我:
事实是抛出它的地方是这样的: public Article[] Select(int number) { return DbContextProvider.Current.Set<Article>() .OrderByDescending(n => n.CreateDate) .Take(number) .ToArray(); } SystemString没有任何用处.实际上,它转换为字符串的唯一地方是: @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,"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等 解决方法
正如亚历山大·科普林格所提到的,似乎是Mono中“datetime2”的错误.通过从MsSql迁移到PostgreSql来修复 – 它在计划中.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读