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')))");
}
我收到此错误The required column 'int_CommodityPriceId' does not exist in the results.
知道为什么会这样做。 (我的dbml文件确实有CommodityPriceId列)。我正在使用linq to sql和vs 2010.running它在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
答案 0 :(得分:2)
此代码尝试将结果分配给CommodityPrice
实体。
为此,它需要返回CommodityPrice
实体列属性中定义的所有列。您的查询不会返回任何列。
如果您只想返回这两个字段,则需要一个仅包含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')))");
}