次のストアプロシージャがあります。
ALTER PROCEDURE [dbo].[SP_BuscarBien_servicio]
@campo varchar(50),
@numPags int,
@numRegs int
AS
BEGIN
SELECT TOP (@numRegs)
[Project1].[BS_Id] AS [BS_Id],
[Project1].[BS_Descripcion] AS [BS_Descripcion],
[Project1].[UNM_Id] AS [UNM_Id],
[Project1].[BS_CostoPromedio] AS [BS_CostoPromedio],
[Project1].[BSTIP_Id] AS [BSTIP_Id],
[Project1].[UNM_Id1] AS [UNM_Id1],
[Project1].[UNM_Descripcion] AS [UNM_Descripcion],
[Project1].[BSTIP_Id1] AS [BSTIP_Id1],
[Project1].[BSTIP_Descripcion] AS [BSTIP_Descripcion]
FROM (
SELECT [Project1].[BS_Id] AS [BS_Id],
[Project1].[BS_Descripcion] AS [BS_Descripcion],
[Project1].[UNM_Id] AS [UNM_Id],
[Project1].[BS_CostoPromedio] AS [BS_CostoPromedio],
[Project1].[BSTIP_Id] AS [BSTIP_Id],
[Project1].[UNM_Id1] AS [UNM_Id1],
[Project1].[UNM_Descripcion] AS [UNM_Descripcion],
[Project1].[BSTIP_Id1] AS [BSTIP_Id1],
[Project1].[BSTIP_Descripcion] AS [BSTIP_Descripcion],
row_number() OVER (ORDER BY [Project1].[BS_Descripcion] ASC) AS [row_number]
FROM ( SELECT
[Extent1].[BS_Id] AS [BS_Id],
[Extent1].[BS_Descripcion] AS [BS_Descripcion],
[Extent1].[UNM_Id] AS [UNM_Id],
[Extent1].[BS_CostoPromedio] AS [BS_CostoPromedio],
[Extent1].[BSTIP_Id] AS [BSTIP_Id],
[Extent2].[UNM_Id] AS [UNM_Id1],
[Extent2].[UNM_Descripcion] AS [UNM_Descripcion],
[Extent3].[BSTIP_Id] AS [BSTIP_Id1],
[Extent3].[BSTIP_Descripcion] AS [BSTIP_Descripcion]
FROM [dbo].[Bien_servicio] AS [Extent1]
INNER JOIN [dbo].[Unidad_Medida] AS [Extent2] ON [Extent1].[UNM_Id] = [Extent2].[UNM_Id]
LEFT OUTER JOIN [dbo].[Bs_tipo] AS [Extent3] ON [Extent1].[BSTIP_Id] = [Extent3].[BSTIP_Id]
WHERE [Extent1].[BS_Descripcion] like '%'+ @campo + '%'
or [Extent2].[UNM_Descripcion] like '%'+ @campo + '%'
or [Extent1].[BS_CostoPromedio] like '%'+ @campo + '%'
or [Extent3].[BSTIP_Descripcion] like '%'+ @campo + '%'
) AS [Project1]
) AS [Project1]
WHERE [Project1].[row_number] > (@numPags - 1)*@numRegs
ORDER BY [Project1].[BS_Descripcion] ASC
END
この関数でインポートされるもの:
public static List<Bien_servicio> ListarBien_servicio(int numPags, int numRegs, String campo = "")
{
try
{
using (SampleDBEntities db = new SampleDBEntities())
{
return db.BuscarBien_servicio(campo, numPags, numRegs).ToList();
}
}
catch (Exception)
{
throw;
}
}
次の関係を使用して
Bs_tipo --< Bien_servicio >--- Unidad_Medida
関連エンティティ (Bien_Servicio.Bs_Tipo) を取得しようとすると、「ObjectContext インスタンスが破棄されたため、接続が必要な操作には使用できなくなりました」というエラーが表示されます。
データベース層では、関連するエンティティは正しくマップされますが、winform コードでは、接続が失われたようにこの例外が発生します。
これはストアド プロシージャで発生します (db.Bien_Servicio.Include("Bs_tipo").ToList(); を使用する場合は問題ありません)。結果を .ToList() に変換しても。私のエラーは何ですか?
前もって感謝します。