向Entity框架模型图添加类会产生错误“类型或命名空间名称< class>无法找到“ [英] Adding class to Entity framework model diagram gives error "The type or namespace name <class> could not be found "

查看:75
本文介绍了向Entity框架模型图添加类会产生错误“类型或命名空间名称< class>无法找到“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个项目,我在一个名为 App_code 的文件夹中设置了Entity Framework模型。



我之前添加了5个类(表)没有问题,但是当我尝试添加 PostCodesUK 然后编译我得到此错误:



 错误  1 类型 命名空间名称无法找到'  PostCodesUK'(您是否缺少使用指令或汇编参考?)d:\ Benen \documents\visual studio 2013 \Projects \ DrogWalks \DogWalks\App_Code \ WalksModel.Context.cs 32 30 DogWalks  





我不能似乎这就是问题所在。我看下 WalksModel.edmx> WalksModel.tt 我可以看到班级 PostCodesUK.cs 。但是,这个类没有任何节点,不像其他节点,我可以扩展节点并查看它们的属性。



另一件事是如果我查看WalksModel.Context.cs我可以看到:



 命名空间 DogWalks.App_Code 
{
使用系统;
使用 System.Data.Entity;
使用 System.Data.Entity.Infrastructure;

public partial class WalksContext:DbContext
{
public WalksContext()
base name = WalksContext
{
}

受保护 覆盖 void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet< Comment>评论{获取; set ; }
public virtual DbSet< DogWalk> DogWalks { get ; set ; }
public virtual DbSet< Feature>功能{获取; set ; }
public virtual DbSet< Image>图片{获取; set ; }
public virtual DbSet< Rating>评分{获取; set ; }
public virtual DbSet< PostCodesUK> PostCodesUKs { get ; set ; } // 此处出错
}
}





但是,如果它表示DbSet< postcodesuk> ;,则PostCodesUK下划线并带有相同的错误消息。



这里发生了什么,问题是什么?请帮助,谢谢。



这是PostCodesUK类,看起来与所有其他类相同:



 命名空间 DogWalks.App_Code 
{
使用系统;
使用 System.Collections.Generic;

public partial class PostCodesUK
{
public int PostcodeID {获得; set ; }
public string 邮政编码{ get ; set ; }
public decimal 纬度{ get ; set ; }
public decimal 经度{ get ; set ; }
public string PostcodeNoSpace { get ; set ; }
}
}

解决方案

通过发布的解决方案管理解决它here!

So I've got a project and I've setup the Entity Framework model in a folder called App_code.

I've previously added 5 classes (tables) with no problem, but when I try and add the PostCodesUK and then compile I get this error:

Error   1   The type or namespace name 'PostCodesUK' could not be found (are you missing a using directive or an assembly reference?)   d:\Ben\documents\visual studio 2013\Projects\DogWalks\DogWalks\App_Code\WalksModel.Context.cs   32  30  DogWalks



I can't seem to this what the issue is. I look under WalksModel.edmx > WalksModel.tt and I can see the class PostCodesUK.cs. However, this class doesn't have any nodes, unlike the ALL the others, where I can expand the node and see their properties.

The other thing is if I look in the WalksModel.Context.cs I can see:

namespace DogWalks.App_Code
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

    public partial class WalksContext : DbContext
    {
        public WalksContext()
            : base("name=WalksContext")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }
        public virtual DbSet<Comment> Comments { get; set; }
        public virtual DbSet<DogWalk> DogWalks { get; set; }
        public virtual DbSet<Feature> Features { get; set; }
        public virtual DbSet<Image> Images { get; set; }
        public virtual DbSet<Rating> Ratings { get; set; }
        public virtual DbSet<PostCodesUK> PostCodesUKs { get; set; } //error here
    }
}



However, where it says DbSet<postcodesuk>, the PostCodesUK is underlined with the same error message above.

What is happening here, what is the problem? Please help, thanks.

Here is the PostCodesUK class, which looks identical to all other classes:

namespace DogWalks.App_Code
{
    using System;
    using System.Collections.Generic;

    public partial class PostCodesUK
    {
        public int PostcodeID { get; set; }
        public string Postcode { get; set; }
        public decimal Latitude { get; set; }
        public decimal Longitude { get; set; }
        public string PostcodeNoSpace { get; set; }
    }
}

解决方案

Managed to solve it with the solution posted here!


这篇关于向Entity框架模型图添加类会产生错误“类型或命名空间名称&lt; class&gt;无法找到“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆