1

我对以下代码有疑问:

public static IQueryable<Osoba> GetOsoby()
{
    using (WeryfikacjaEntities context = new WeryfikacjaEntities())
    {
        IQueryable<Osoba> user = from s in context.Osobas select s;
        return user;
    }
}

实际上问题发生在第三行,具体在:

WeryfikacjaEntities context = new WeryfikacjaEntities()

我收到一个异常,其内部异常显示类似(不能粘贴它,除非你知道波兰语):“找不到在配置中命名的给定连接,此连接不应该与 EntityClient 提供程序一起使用或不正确”。

异常本身给了我一些关于 XamlParse 的信息

我用过EntityFramework向导,所以我猜连接没问题。任何想法如何解决它?

GetOsoby()方法是这样调用的:

public static List<Worker> GetWorkers()
{
    var u = Class1.GetOsoby().Select(x => new Worker
    {
        _id = x.ID,
        _name = x.Imie,
        _surname = x.Nazwisko,
        _birthDate = x.DataUrodzenia,
        _position = x.Stanowisko,
        _earnings = x.Wynagrodzenie,
        _ageGroup = x.GrupaWiekowa,
        _department = Class1.GetDzialy().Where(
            y => y.ID == Class1.GetStanowiska().Where(
                z => z.ID == x.Stanowisko).FirstOrDefault().ID)
            .FirstOrDefault().ID
    }).ToList();

    return (List<Worker>)u;
}

这是内部异常的 Stacktrace:

   in System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
   in System.Data.EntityClient.EntityConnection..ctor(String connectionString)
   in System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString)
   in System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)
   in ClassLibrary1.WeryfikacjaEntities..ctor() w C:\Users\Rufix\documents\visual studio 2010\Projects\Zadanie 5\ClassLibrary1\Model1.Designer.cs:wiersz 40
   in ClassLibrary1.Class1.GetOsoby() w C:\Users\Rufix\documents\visual studio 2010\Projects\Zadanie 5\ClassLibrary1\Class1.cs:wiersz 13
   in Zadanie_5.Worker.GetWorkers() w C:\Users\Rufix\documents\visual studio 2010\Projects\Zadanie 5\Zadanie 5\Worker.cs:wiersz 39
   in Zadanie_5.MainWindow..ctor() w C:\Users\Rufix\documents\visual studio 2010\Projects\Zadanie 5\Zadanie 5\MainWindow.xaml.cs:wiersz 26

TargetSite: {Void ChangeConnectionString(System.String)}
4

1 回答 1

0

声明上下文时,您可以指定连接字符串,并且可以像这样声明数据库上下文:

public class DatabaseContext : DbContext
    {
        public DatabaseContext() : base("SomeConnectionString"){}
    {

你确定你正在调用正确的连接字符串吗?

如果没有,请粘贴内部异常的其余部分,以便我们查看

于 2012-06-05T01:21:31.450 回答