How to convert following query from sql(Oracle) to linq-to-entities:
select * FROM ActivityPromptText where ActivityId = 8
and ProcessTypeId = 1 and ProcessId is null
When I am writing this c#, its returning null
, while same query is returning result in sql.
The Linq query is:
var text2 = this.context.ActivityPromptText
.Where(pt => (pt.ActivityId == activityId && pt.ProcessTypeId == processType)
&& pt.ProcessId == null)
.Include(pt => pt.Prompt).FirstOrDefault();
=======================
The MODELS are:
[Table("ActivityPromptText")]
public class ActivityPromptText
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[Column(Order = 1)]
public int PromptTextId { get; set; }
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[Column(Order = 2)]
public int ActivityId { get; set; }
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[Column(Order = 3)]
public int ProcessTypeId { get; set; }
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[Column(Order = 4)]
public int? ProcessId { get; set; }
[ForeignKey("PromptTextId")]
public virtual PromptText MbopPrompt { get; set; }
}
and:
[Table("PromptText")]
public class PromptText
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int PromptTextId { get; set; }
public string PromptText { get; set; }
}
and The DBContext file has:
public virtual DbSet ActivityPromptTexts { get; set; }
public virtual DbSet PromptTexts { get; set; }
ProcessTypeId
&ProcessId
? It change the query right? Change it like this and try:-.Where(pt => pt.ActivityId == activityId && pt.ProcessTypeId == processType && pt.ProcessId == null)
Prompt
andActivityPromptText
?