我遇到以下代码问题:
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
向导,所以我猜连接没问题。
任何想法如何解决它?
以这种方式调用Oh 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)}
答案 0 :(得分:0)
声明上下文时,您可以指定连接字符串,并且可以像这样声明数据库上下文:
public class DatabaseContext : DbContext
{
public DatabaseContext() : base("SomeConnectionString"){}
{
您确定要调用正确的连接字符串吗?
如果没有,请粘贴内部异常的其余部分,以便我们可以看到它