I’ve created entity data model for the following database tables in SqlCe:
CREATE TABLE [test_vulnerabilities] (
[id] INTEGER PRIMARY KEY,
[description] NTEXT NOT NULL DEFAULT ''
);
CREATE TABLE [test_software_vulnerabilities]
(
[id] INTEGER PRIMARY KEY IDENTITY,
[vulnerability_id] INTEGER NOT NULL
REFERENCES [test_vulnerabilities]([id]),
[details] NTEXT NOT NULL DEFAULT ''
);
Entities (created by adding entity model based on existing database):
entity Vulnerability in set Vulnerabilities
Id int
Description string
Software ICollection<SoftwareVulnerability> - navigation property
entity SoftwareVulnerability in set SoftwareVulnerabilities
Id int
Details string
VulnerabilityId int
Vulnerability Vulnerability - navigation property
and executing the following query:
var query = (from v in entities.Vulnerabilities.Include("Software")
where v.Id == id && v.Software.Count > 0
select v);
it is very-very-very slow because the generated SQL joins vulnerabilities with software_vulnerability with left outer join.
Is there any way to simply say that I want only vulnerabilities with non-empty software_vulnerability and the INNER JOIN is ok?
Thanks!
No. You don’t have control over used joins. You can try to revert the query:
You will get all software vulnerabilities for your single expected vulnerability and the vulnerability will be included. If your relation is from software vulnerability is correctly configured as mandatory it should hopefully use inner join.