这是我的第一个使用entityFramework和LinQ的项目,我无法开发此简单功能。
我想从两个表中制作一个简单的inner join
:
public partial class DEGENZE_OSPITE
{
[Key]
public int ID_DEGENZA { get; set; }
public int ID_OSPITE { get; set; }
public int ID_TIPO_DEGENZA { get; set; }
public int ID_TIPO_CAMERA { get; set; }
public virtual ANAG_TIPO_DEGENZA ANAG_TIPO_DEGENZA { get; set; }
public virtual ANAG_OSPITI ANAG_OSPITI { get; set; }
public virtual ANAG_TIPO_CAMERA ANAG_TIPO_CAMERA { get; set; }
}
public partial class ANAG_TIPO_DEGENZA
{
[Key]
public int ID_TIPO_DEGENZA { get; set; }
[Required]
[StringLength(500)]
public string DESCRIZIONE { get; set; }
[Required]
[StringLength(10)]
public string INIZ_CAMPO_COSTI { get; set; }
public virtual DEGENZE_OSPITE DEGENZE_OSPITE { get; set; }
}
但是我生成的dbcontext.sql是:
SELECT
[Project1].[ID_DEGENZA] AS [ID_DEGENZA],
..
FROM ( SELECT
[Extent1].[ID_DEGENZA] AS [ID_DEGENZA],
..
FROM [AnagOspiti].[DEGENZE_OSPITE] AS [Extent1]
LEFT OUTER JOIN [dbo].[ANAG_TIPO_CAMERA] AS [Extent2] ON [Extent1].[ID_DEGENZA] = [Extent2].[ID_TIPO_CAMERA]
LEFT OUTER JOIN [AnagOspiti].[ANAG_TIPO_DEGENZA] AS [Extent3] ON [Extent1].[ID_DEGENZA] = [Extent3].[ID_TIPO_DEGENZA]
WHERE [Extent1].[ID_OSPITE] = @p__linq__0
) AS [Project1]
ORDER BY [Project1].[DATA_DAL] ASC
错误在left outer join
和此处
LEFT OUTER JOIN [AnagOspiti].[ANAG_TIPO_DEGENZA] AS [Extent3] ON [Extent1].[***ID_DEGENZA***] = [Extent3].[***ID_TIPO_DEGENZA***]
我需要的是
INNER JOIN [AnagOspiti].[ANAG_TIPO_DEGENZA] AS [Extent3] ON [Extent1].[ID_TIPO_DEGENZA] = [Extent3].[ID_TIPO_DEGENZA]
错误在哪里? 我必须使用1对N的关系? 抱歉,我是entityframework e LinQ的新用户。