Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The only way I can see which might come close at least to a "relationship without navigation properties" is creating the FK contraint in the database with a hand-written migration, like so:</p> <pre><code>using System; using System.Data.Entity.Migrations; public partial class CreateCompanyAndEmployee : DbMigration { public override void Up() { CreateTable( "Companies", c =&gt; new { Id = c.Guid(nullable: false), CompanyName = c.String(nullable: false, maxLength: 100) }) .PrimaryKey(t =&gt; t.Id); CreateTable( "Employees", c =&gt; new { Id = c.Guid(nullable: false), Name = c.String(nullable: false, maxLength: 100), CompanyId = c.Guid(nullable: false) }) .PrimaryKey(t =&gt; t.Id); AddForeignKey("Employees", "CompanyId", "Companies", "Id"); CreateIndex("Employees", "CompanyId"); } //... } </code></pre> <p>Since you have no navigation properties you must use joins with LINQ-to-Entities if you ever want to load for example a company including all related employees, like this for instance:</p> <pre><code>var companiesWithEmployees = context.Companies .GroupJoin(context.Employees, company =&gt; company.Id, employee =&gt; employee.CompanyId, (company, employees) =&gt; new { Company = company, Employees = employees }) .ToList(); </code></pre> <p>You always must specify the property <code>employee.CompanyId</code> explicitly that represents the foreign key in such joins. EF is not aware that the <code>CompanyId</code> is a foreign key property. It's just an ordinary scalar property in the EF model without any relationship meaning.</p> <p><code>companiesWithEmployees</code> would be a collection of anonymous objects. Each object contains a <code>Company</code> entity and a collection <code>IEnumerable&lt;Employee&gt;</code> of the employees related with that company.</p> <p>However, I fail to see the benefit of avoiding navigation properties.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload