【发布时间】:2016-02-04 23:09:07
【问题描述】:
奇怪的是,我已经添加了 5 个表没有问题。但是,当我尝试通过我的 edmx 模型添加我的 PostCodesUK 表时,它给了我这个错误消息:
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 33 30 DogWalks
不确定发生了什么,但有一些细微的差别。例如,如果我在 WalksModel.tt 类下查看,我可以看到 PostCodesUK 类,但它没有生成额外的“存根”:
如果我然后双击上面的错误,它会将我带到WalksModel.Context.cs,在那里我看到了这个错误:
我查看了PostCodesUK.cs 类下的namespace,它与其他类匹配。有谁知道问题是什么?我在网上搜索了这个问题,但找不到解决方案。
更新: PostCodeUK 类如下所示:
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; }
}
}
此外,我在我的模型中添加了另一个临时表(Person)来测试它,它也给了我与 PostCodesUK 相同的错误消息:
public virtual DbSet<Comment> Comments { get; set; }
...
public virtual DbSet<PostCodesUK> PostCodesUKs { get; set; } //error
public virtual DbSet<Person> People { get; set; } //error
【问题讨论】:
-
我对此投了赞成票,因为我过去遇到过同样的问题;但不记得我是如何解决的。
-
PostCodesUK 类是什么样的?检查它是否公开。检查命名空间是否也不是 PostCodesUK(因为您需要键入 DbSet
)。如果没有,请检查您的解决方案中是否还没有命名空间 PostCodesUK。 -
@tzachs 感谢您的评论。我现在已将类添加到答案中(该类通常看起来像所有其他类(命名空间相同)。奇怪的是,当我尝试添加另一个类时,我遇到了同样的错误,这可能会排除命名空间冲突? 的
-
@Brian 谢谢。这很奇怪。我刚刚尝试添加另一个新表,它也给了我同样的错误信息......非常奇怪
标签: c# asp.net entity-framework webforms ado.net