3

在 VS 2012 下的 MVC 3 解决方案中,在运行代码分析后收到这样的消息听起来很奇怪:

在此处输入图像描述

这很奇怪,因为“不要”分析中提到的类是由 VS 本身(不是我)生成的。

要重现这一点,您可以:

  1. ADO.NET 实体数据模型添加到您的解决方案中,
  2. 将您的数据库表(已经存在于 SQL Server 中)添加到图表中,
  3. 重建解决方案,添加控制器和 cshtml 视图(那些是自动生成的)。
  4. 从 ANALYZE 菜单运行代码分析。

所以,问题是,我们能做什么:重构自动生成的代码还是忽略这个消息?

下面是违反规则 CA2214 的自动生成类的示例:

//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Backoffice.Entities
{
    using System;
    using System.Collections.Generic;

    public partial class BR_SIMUL_Supermarket_Product
    {
        public BR_SIMUL_Supermarket_Product()
        {
            this.BR_SIMUL_Supermarket_Product_Price = new HashSet<BR_SIMUL_Supermarket_Product_Price>();
        }

        public int product_id { get; set; }
        public int category_id { get; set; }
        public string product_name { get; set; }
        public string product_measure { get; set; }
        public bool product_active { get; set; }
        public virtual BR_SIMUL_Supermarket_Category BR_SIMUL_Supermarket_Category { get; set; }
        more stuff here...
4

3 回答 3

2

这是我永久解决它的方法:http ://chuckbeasley.com/blog/?p=42200

于 2015-03-11T00:46:37.993 回答
1

你应该随意压制这些。有关更多详细信息,请查看 Entity Framework codeplex 站点上的此讨论。

于 2013-01-15T00:58:13.543 回答
1

这是为了允许延迟加载而设计的。当您通过它访问类DbContext时,尽管有警告,它不会在运行时失败。您应该仅在这些文件中禁止显示警告。

于 2013-06-10T07:16:41.757 回答