必需的列“int_CommodityPriceId”结果中不存在。 LINQ 到 SQL

发布于 2024-12-04 16:16:11 字数 1035 浏览 1 评论 0原文

public IEnumerable<CommodityPrice> GetAllTimeFrameDaily()
    {
        return _dbprice.ExecuteQuery<CommodityPrice>("SELECT MIN(CommodityPrice.dtm_Date),MAX(CommodityPrice.dtm_Date) FROM CommodityPrice WHERE (CommodityPrice.int_FrequencyId = 1) and int_MarketLocationId in (SELECT [int_LocationId] FROM [Location] where int_LocationTypeId=4  and int_ParentLocationId in (SELECT [int_LocationId] FROM [Location] where int_LocationTypeId=2 and int_ParentLocationId in (SELECT int_LocationId FROM [Location] where int_LocationTypeId = 1 and vcr_LocationEn='Pakistan')))");
    }

我收到此错误结果中不存在所需的列“int_CommodityPriceId”。知道为什么要这样做。 (我的 dbml 文件确实有 CommodityPriceId 列)。我正在使用 linq to sql 和 vs 2010.在 sql server 中的运行文件中运行它

commodityprice

int_CommodityPriceId bigint Unchecked
int_CommodityId bigint  Checked
int_SourcesId   int Checked
int_MarketLocationId    int Checked
int_FrequencyId int Checked
flt_Price   float   Checked
flt_PriceUSD    float   Checked
public IEnumerable<CommodityPrice> GetAllTimeFrameDaily()
    {
        return _dbprice.ExecuteQuery<CommodityPrice>("SELECT MIN(CommodityPrice.dtm_Date),MAX(CommodityPrice.dtm_Date) FROM CommodityPrice WHERE (CommodityPrice.int_FrequencyId = 1) and int_MarketLocationId in (SELECT [int_LocationId] FROM [Location] where int_LocationTypeId=4  and int_ParentLocationId in (SELECT [int_LocationId] FROM [Location] where int_LocationTypeId=2 and int_ParentLocationId in (SELECT int_LocationId FROM [Location] where int_LocationTypeId = 1 and vcr_LocationEn='Pakistan')))");
    }

i am getting this error The required column 'int_CommodityPriceId' does not exist in the results. any idea why it is doing this. (my dbml file do have the CommodityPriceId column). i am using linq to sql and vs 2010.running it in running file in sql server

commodityprice

int_CommodityPriceId bigint Unchecked
int_CommodityId bigint  Checked
int_SourcesId   int Checked
int_MarketLocationId    int Checked
int_FrequencyId int Checked
flt_Price   float   Checked
flt_PriceUSD    float   Checked

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怼怹恏 2024-12-11 16:16:11

此代码尝试将结果分配给 CommodityPrice 实体。
为此,它需要返回 CommodityPrice 实体列属性中定义的所有列。您的查询不会返回其中任何列。

如果您只想返回这 2 个字段,您将需要一个仅包含 2 个日期字段的新实体..

TimeFrame
dte_CommodityPriceMinDate  datetime  Unchecked
dte_CommodityPriceMaxDate  datetime  Checked

并且查询应填充此字段:

public IEnumerable<TimeFrame> GetAllTimeFrameDaily()
    {
        return _dbprice.ExecuteQuery<TimeFrame>("SELECT MIN(CommodityPrice.dtm_Date) AS dte_CommodityPriceMinDate ,MAX(CommodityPrice.dtm_Date) AS dte_CommodityPriceMaxDate FROM CommodityPrice WHERE (CommodityPrice.int_FrequencyId = 1) and int_MarketLocationId in (SELECT [int_LocationId] FROM [Location] where int_LocationTypeId=4  and int_ParentLocationId in (SELECT [int_LocationId] FROM [Location] where int_LocationTypeId=2 and int_ParentLocationId in (SELECT int_LocationId FROM [Location] where int_LocationTypeId = 1 and vcr_LocationEn='Pakistan')))");
    }

This code is attempting to assign the results to a CommodityPrice entity.
In order to do this, it needs to return all of the columns defined in the CommodityPrice entity column properties.. Your query doesn't return ANY of them..

If you just want to return these 2 fields, you'll need a new entity containing just 2 date fields..

TimeFrame
dte_CommodityPriceMinDate  datetime  Unchecked
dte_CommodityPriceMaxDate  datetime  Checked

and the query should populate this instead:

public IEnumerable<TimeFrame> GetAllTimeFrameDaily()
    {
        return _dbprice.ExecuteQuery<TimeFrame>("SELECT MIN(CommodityPrice.dtm_Date) AS dte_CommodityPriceMinDate ,MAX(CommodityPrice.dtm_Date) AS dte_CommodityPriceMaxDate FROM CommodityPrice WHERE (CommodityPrice.int_FrequencyId = 1) and int_MarketLocationId in (SELECT [int_LocationId] FROM [Location] where int_LocationTypeId=4  and int_ParentLocationId in (SELECT [int_LocationId] FROM [Location] where int_LocationTypeId=2 and int_ParentLocationId in (SELECT int_LocationId FROM [Location] where int_LocationTypeId = 1 and vcr_LocationEn='Pakistan')))");
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文