我已经缩小到一个简单的方法,我试图从实体模型中填充一个 Observable 集合。我不知道我这样做是否正确。
注意:这似乎是设计者错误。我可以构建和运行程序......所以它出现了。
private ObservableCollection<LessonGroup> lessonGroups;
public ObservableCollection<LessonGroup> LessonGroups
{
get { return LessonGroups; }
set { lessonGroups = value; RaisePropertyChanged("LessonGroups"); }
}
private void GetLessonGroups()
{
//this using statement causes ArgumentException
using (MyEntities ae = new MyEntities())
{
foreach (LessonGroup lg in ae.LessonGroups)
{
LessonGroups.Add(lg);
}
}
}
例外情况如下:
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
at System.Data.EntityClient.EntityConnection..ctor(String connectionString)
at System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString)
at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)
at IMPACT.ARCTrainer.Model.ARCTrainerEntities..ctor() in C:\Users\Leland\Documents\Visual Studio 2010\Projects\ARCTrainer\Model\ARCTrainer.Designer.cs:line 56
at IMPACT.ARCTrainer.ViewModel.LessonsViewModel.GetLessonGroups() in C:\Users\Leland\Documents\Visual Studio 2010\Projects\ARCTrainer\ViewModel\LessonsViewModel.cs:line 171
at IMPACT.ARCTrainer.ViewModel.LessonsViewModel..ctor(ViewModelLocator viewModelLocator) in C:\Users\Leland\Documents\Visual Studio 2010\Projects\ARCTrainer\ViewModel\LessonsViewModel.cs:line 37
at IMPACT.ARCTrainer.ViewModel.ViewModelLocator..ctor() in C:\Users\Leland\Documents\Visual Studio 2010\Projects\ARCTrainer\ViewModel\ViewModelLocator.cs:line 46