2009-10-24 82 views
1

我有一个奇怪的问题,我无法找出一个解决方案:使用ObjectDataProvider的具有约束力源给出了SQL错误

我做了写在使用某个连接的SQL Server Express C#有点WPF应用程序。 mdf数据库,然后我通过LINQ操纵。

我在表单上有一个ListView,它的datacontext设置为.DataContext = dr.FindAllBuyOrders(),它返回一个IQueryable BuyOrder对象。这一切工作正常。然而,当我做同样通过XAML与ObjectDataProvider的:

<ObjectDataProvider MethodName="FindAllBuyOrders" ObjectType="{x:Type local:DataRepository}" x:Key="dataBuyOrders" /> 

<ListView Name="listViewBuyOrders" VerticalContentAlignment="Top" ItemsSource="{Binding Source={StaticResource dataBuyOrders}}" ItemTemplate="{StaticResource listViewBuyOrders}"> 
    <ListView.ItemsPanel> 
     <ItemsPanelTemplate> 
      <WrapPanel /> 
     </ItemsPanelTemplate> 
    </ListView.ItemsPanel> 
</ListView> 

然后我得到以下错误:

An attempt to attach an auto-named database for file 
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Data.mdf 
failed. A database with the same name exists, or specified file 
cannot be opened, or it is located on UNC share. 

回答