簡體   English   中英

System.Data.Entity.Infrastructure.DbRawSqlQuery <>不包含“包含”的定義

[英]System.Data.Entity.Infrastructure.DbRawSqlQuery<> does not contain a definition for 'Include'

我正在使用ASP.NET MVC,實體框架和WCF開發音樂商店示例應用程序。

數據庫層中的用戶只想從數據庫中提取檢索類型和其相關專輯。

因此使用此方法,使用存儲過程“ GetAllGenres”獲取所有流派

CREATE PROCEDURE GetAllGenres
AS
BEGIN       

   SELECT [GenreId]
      ,[Name]
      ,[Description]
  FROM [dbo].[Genres]

END
GO

訪問上述存儲過程的方法是

public static Genre BrowseGenre(string genre)
        {
            using (MusicStoreEntities db = new MusicStoreEntities())
            {
                return db.Database.SqlQuery<Genre>("GetAllGenres").Include("Albums").Single(g => g.Name == genre);
            }
        }

我收到以下錯誤

System.Data.Entity.Infrastructure.DbRawSqlQuery'不包含'Include'的定義,也沒有擴展方法'Include'

如何解決?

最終結論,因為SqlQuery沒有Include方法

public static Genre BrowseGenre(string genre)
        {
            using (MusicStoreEntities db = new MusicStoreEntities())
            {
                //return db.Database.SqlQuery<Genre>("GetAllGenres").Include("Albums").Single(g => g.Name == genre);
                return db.Genres.Include("Albums").Single(g => g.Name == genre);
            }                
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM