【问题标题】:Using ObjectDataProvider as binding source gives SQL error使用 ObjectDataProvider 作为绑定源会产生 SQL 错误
【发布时间】:2009-10-24 11:22:12
【问题描述】:

我有一个奇怪的问题,我无法找到解决方案:

我制作了一个用 C# 编写的小 WPF 应用程序,它使用附加的 SQL Server Express .mdf 数据库,然后我通过 LINQ 对其进行操作。

我在表单上有一个 ListView,它的 datacontext 设置为 .DataContext = dr.FindAllBuyOrders(),它返回一个 IQueryable BuyOrder 对象。这一切都很好。但是,当我使用 ObjectDataProvider 通过 xaml 执行相同操作时:

<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.

【问题讨论】:

    标签: wpf xaml sql-server-express objectdataprovider


    【解决方案1】:

    我找到了解决办法:

    连接字符串与数据库的相对路径而不是绝对路径一起存储。在此链接中查看更多信息:

    Embedding SQL Express to use with Linq to SQL and User Instances can be a pain

    【讨论】:

      猜你喜欢
      • 2010-09-14
      • 1970-01-01
      • 1970-01-01
      • 2016-01-06
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      • 2013-09-04
      • 1970-01-01
      相关资源
      最近更新 更多