Create LINQ association without foreign keys

Is it possible to have something like ContactAddress.Contact in LINQ without creating a foreign key relationship in SQL Server between the two (which could be related to Contact.Id ↔ ContactAddress.ContactId)?

Thanks:)

+3
source share
2 answers

If you want to create relations on your object-relational map (even if these relations do not exist in the database as a declared foreign key), you can do this using the Object-Relational constructor.

http://msdn.microsoft.com/en-us/library/bb629295.aspx

+3
source

, , . , LINQ to SQL, , :

from category in db.Categories
from product in category.Products
select new
{
    Category = category,
    Product = product
}

T-SQL, :

from category in db.Categories
join product in db.Products on category.CategoryId equals product.CategoryId
select new
{
    Category = category,
    Product = product
}

:

SELECT
    *
FROM
    Category INNER JOIN Product ON Category.CategoryId = Product.CategoryId

, .

+4

Source: https://habr.com/ru/post/1709935/


All Articles