【问题标题】:WCF-project will not return data with 64-bit Win Vista and VS2010WCF-project 将不会返回 64 位 Win Vista 和 VS2010 的数据
【发布时间】:2012-07-17 09:12:33
【问题描述】:

当我找到this 时,我以为我找到了解决问题的方法,但它对我不起作用。

当我在调试模式下运行时,我的WcfTestClient 没有检索到任何数据并且我收到错误消息:

A first chance exception of type 'System.NotSupportedException' occurred in System.Data.Entity.dll
The thread '<No Name>' (0x1b50) has exited with code 0 (0x0).
The program '[7040] WCFTestClient.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).....................................

检索数据的方法如下:

public List<WShortDeal> Test()
    {
        try
        {
            return entities.ProductInstance_Deal
                .Select(d => new WShortDeal()
                {
                    Id = d.Deal.Id
                   // ,
                   // Name = d.Deal.Deal_Language.SingleOrDefault(l => l.Language.Id == 1).Name**
                    ,
                    NewPrice = (double)d.ProductInstance.Price * (1 - d.Deal.SalesPercentage / 100)
                    ,
                    OldPrice = (double)d.ProductInstance.Price
                    ,
                    Valuta = d.ProductInstance.Valuta.ValutaCode
                    ,
                    Type = d.Deal.Type
                    ,
                    IdCompanyAccount = d.ProductInstance.IdCompanyAccount
                })
                    .ToList();
        }
        catch (Exception)
        {
            return null;
        }
    }

如果我取消注释现在被注释掉的两行,我将停止接收数据并在我的输出窗口中收到上述错误消息。

如果我添加这一行

  ,ProductCategory = d.ProductInstance.ProductType.ProductCategory.ProductCategory_Language.Where(pcl => pcl.IdLanguage == idLanguage).Single().Name

而不是行

 , Name = d.Deal.Deal_Language.SingleOrDefault(l => l.Language.Id == 1).Name

对于我原来的 SELECT 语句,它也不会返回任何数据。所以我想这可能与代表与我的语言表(??)的多对多关系的所有表有关。因为每当我忘记与“ProductCategory_Language”表的连接时,我都可以再次检索数据。

有人可以帮忙吗?我的问题还有其他解决方案吗?这几天我一直在为这个问题苦苦挣扎:( 提前致谢。

【问题讨论】:

  • 从外观上看,这似乎不是 WCF 问题。 System.Data.Entity.dll 中发生“System.NotSupportedException”...这可能表明您的数据模型存在问题。您的模型是否与您的数据库同步?还尝试将 Deal_Language 选择部分重构为单独的实用程序方法。这样可以帮助您更好地调试。
  • @CSharpenter 感谢您的反应;我会试一试............我一直在努力让我的模型同步,这是真的!我会让你知道的。问:如何“将 Deal_Language 选择部分重构为单独的实用方法”?
  • private string ExtractLanguageName(DealEntityType deal, int langID) // 将 DealEntityType 替换为 Deal 的真实类型 { var deal_Lang = deal.Deal_Language.SingleOrDefault(l => l.Language.Id == langID) ; if (deal_Lang != null) { return deal_Lang.Name; } 返回字符串。空; // 或抛出异常,或其他动作 }
  • // 名称 = ExtractLanguageName(d.Deal, 1); // 而不是 // Name = d.Deal.Deal_Language.SingleOrDefault(l => l.Language.Id == 1).Name**
  • @CSharpenter 再次感谢!我试过了......仍然没有运气:(虽然我发现了一些新东西。请参阅上面我原来问题的编辑

标签: wcf linq 64-bit windows-vista


【解决方案1】:

如果该行在选择名称之前返回 null 怎么办? 试试

  Name = d.Deal.Deal_Language.Where(l => l.Language.Id == 1)
         .Select(s=>s.Name).SingleOrDefault()

【讨论】:

    猜你喜欢
    • 2013-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-24
    • 2010-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多