Code: Select all
public partial class Maintable
{
public int Id { get; set; }
public int ConnectionID { get; set; }
public string Name { get; set; }
public string Value { get; set; }
}
public partial class Jointable
{
public int Id { get; set; }
public int ConnectionID { get; set; }
public string Value { get; set; }
}
Code: Select all
var model = from mt in db.Maintable
join jt in db.Jointable on mt.ConnectionID equals jt.ConnectionID into gj
from x in gj.DefaultIfEmpty()
select new {
mt,
mt.Value = x != null ? x.Value : "" }
< /code>
Modell sollte nur das Haupttabellenobjekt zurückgeben. < /p>
Das SQL -Äquivalent sollte so sein:SELECT
mt.Id AS ID,
mt.ConnectionID AS ConnectionID,
mt.Name AS Name,
jt.Value AS Value
FROM
Maintable mt
LEFT JOIN
Jointable jt ON mt.ConnectionID = jt.ConnectionID