Hi, I'm pretty new to WPF and C #, so please be calm if this is just a dumb question:
I am using VS2012, Entity Framework to create a model of a pre-existing database, and I would like to bind some tables to some ListView ... Now I know that there are different ways to do this, but when I try to use ObjectDataProvider, I get a message about error during development "There is no connection string in the application configuration line ...".
It is strange that if I run my application, everything works as it should, I just want to remove this ugly error message and hopefully get the data in my graphic design (that I would like to use ObjectDataProvider).
Here are some parts of my code:
App.Config:
<?xml version="1.0" encoding="utf-8"?> <configuration> <connectionStrings> <add name="BibliotecaEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string='data source=(LocalDB)\v11.0;attachdbfilename="G:\PROGETTI-SOFTWARE\c# tests\Biblioteca\Biblioteca\biblioteca-db.mdf";initial catalog=BibliotecaDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework'" providerName="System.Data.EntityClient" /> </connectionStrings> </configuration>
ListaScaffali.xaml:
<Window x:Class="Biblioteca.ShelvesList" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Biblioteca;assembly=" Title="ShelvesList" Height="341" Width="609"> <Window.Resources> <ObjectDataProvider ObjectType="{x:Type local:BooksDB_Handler}" MethodName="TuttiGliScaffali" x:Key="ScaffaliObjSrc" /> </Window.Resources> <Grid> <Grid> <ListView Name="listaScaffali" ItemsSource="{Binding Source={StaticResource ScaffaliObjSrc}}"> <ListView.View> <GridView> <GridViewColumn Header="Scaffali Disponibili:" DisplayMemberBinding="{Binding Scaffale}" /> </GridView> </ListView.View> </ListView> </Grid> </Grid> </Window>
BooksDB-Handler.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Configuration; using System.Data.Entity; using System.Collections.ObjectModel; namespace Biblioteca { public static class BooksDB_Handler { ... public static ObservableCollection<Scaffali> TuttiGliScaffali() { using (var ctx = new BibliotecaEntities()) { var reader = from d in ctx.Scaffali select d; return new ObservableCollection<Scaffali>(reader); } } ... } }
In my database, the "Scaffali" table has only two columns: "ScaffaliID" (identity) and "Scaffale".
I read somewhere that this could be a Visual Studio error and tried different things:
- rebuild several times
- avoid # in transit
- compilation for 32 bit (I am running Win8 x64)
but still no luck ...
Thanks for your kind reply.
- = UPDATE 03/03/2013 = -
So far, I still have not found what conditions cause this strange behavior, in any case, I found that if I just build (don't rebuild) twice in a row, the error message just disappears and everything seems to work like this as it should ...