-
-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revamped Linq baseline support. Closes GH-2684 Ability to use compiled queries even when the generated SQL uses containment operators or JSONPath queries. Closes GH-2702 WIP: Refactored the Contains() query logic to centralize it a bit Updated to Weasel 6.2, changed the shape of ICompiledQueryAwareFilter to get ready for containment filters Added some test helper for detecting with a Linq query uses a CTE prior to improving child collection queries Cleaning out some ununsed ContainmentWhereFragment code WIP: refactored compiled queries quite a bit to get ready to handle JSONPath & containment operators in compiled queries Revert "tweaking github builds" This reverts commit fdfe09022191923242ca802f0c8449709ec90f1b. maybe fixed some references to code snippets tweaking github builds removing older postgres versions removing older Postgres versions Fixed a likely merge problem w/ the duplicated field doc page Fixed a combination of soft deleted documents being part of an Include() operation Few more fixes for LINQ overhaul regressions Bug fixing for a couple v7 merge issues doc snippet change Fixed new parsers to the v7 linq model
- Loading branch information
1 parent
e9bea56
commit 22d698b
Showing
561 changed files
with
10,640 additions
and
56,398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +0,0 @@ | ||
|
||
BenchmarkDotNet=v0.10.1, OS=Microsoft Windows NT 6.1.7601 Service Pack 1 | ||
Processor=Intel(R) Core(TM) i7-4980HQ CPU 2.80GHz, ProcessorCount=4 | ||
Frequency=10000000 Hz, Resolution=100.0000 ns, Timer=UNKNOWN | ||
[Host] : Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1076.0 | ||
Job-DNINOD : Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1076.0 | ||
|
||
WarmupCount=2 Gen 0=287.5000 Allocated=4.62 MB | ||
|
||
Method | Mean | StdDev | | ||
---------------- |----------- |---------- | | ||
InsertDocuments | 43.7957 ms | 2.6786 ms | | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +0,0 @@ | ||
``` ini | ||
|
||
BenchmarkDotNet=v0.10.1, OS=Microsoft Windows NT 6.1.7601 Service Pack 1 | ||
Processor=Intel(R) Core(TM) i7-4980HQ CPU 2.80GHz, ProcessorCount=4 | ||
Frequency=10000000 Hz, Resolution=100.0000 ns, Timer=UNKNOWN | ||
[Host] : Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1076.0 | ||
Job-DNINOD : Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1076.0 | ||
|
||
WarmupCount=2 | ||
|
||
``` | ||
Method | Mean | StdDev | Gen 0 | Gen 1 | Allocated | | ||
------------------ |---------------- |-------------- |---------- |-------- |---------- | | ||
CreateLinqCommand | 189.7593 us | 2.3160 us | - | - | 42.64 kB | | ||
RunLinqQuery | 124,248.2148 us | 1,785.5957 us | 4975.0000 | - | 34.13 MB | | ||
CompiledQueries | 29,998.1235 us | 719.6757 us | 958.3333 | 83.3333 | 8.71 MB | | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,149 +0,0 @@ | ||
# Foreign Keys | ||
|
||
Marten **is** built on top of a relational database, so why not take advantage of those abilities | ||
where they still add value? In this case, Marten allows for a special kind of "Searchable" column | ||
that also adds a foreign key constraint to enforce referential integrity between document types. | ||
|
||
One of our sample document types in Marten is the `Issue` class that has | ||
a couple properties that link to the id's of related `User` documents: | ||
|
||
<!-- snippet: sample_Issue --> | ||
<a id='snippet-sample_issue'></a> | ||
```cs | ||
public class Issue | ||
{ | ||
public Issue() | ||
{ | ||
Id = Guid.NewGuid(); | ||
} | ||
|
||
public string[] Tags { get; set; } | ||
|
||
public Guid Id { get; set; } | ||
|
||
public string Title { get; set; } | ||
|
||
public int Number { get; set; } | ||
|
||
public Guid? AssigneeId { get; set; } | ||
|
||
public Guid? ReporterId { get; set; } | ||
|
||
public Guid? BugId { get; set; } | ||
public string Status { get; set; } | ||
} | ||
``` | ||
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/Marten.Testing/Documents/Issue.cs#L5-L29' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_issue' title='Start of snippet'>anchor</a></sup> | ||
<!-- endSnippet --> | ||
|
||
If I want to enforce referential integrity between the `Issue` document and the `User` documents, | ||
I can use this syntax shown below to configure Marten: | ||
|
||
<!-- snippet: sample_configure-foreign-key --> | ||
<a id='snippet-sample_configure-foreign-key'></a> | ||
```cs | ||
var store = DocumentStore | ||
.For(_ => | ||
{ | ||
_.Connection("some database connection"); | ||
|
||
// In the following line of code, I'm setting | ||
// up a foreign key relationship to the User document | ||
_.Schema.For<Issue>().ForeignKey<User>(x => x.AssigneeId); | ||
}); | ||
``` | ||
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/Marten.Testing/Examples/ForeignKeyExamples.cs#L11-L21' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_configure-foreign-key' title='Start of snippet'>anchor</a></sup> | ||
<!-- endSnippet --> | ||
|
||
With the configuration above, Marten will make an `assignee_id` field in the database table and build a | ||
foreign key constraint to the `User` document like so: | ||
|
||
```sql | ||
ALTER TABLE public.mt_doc_issue | ||
ADD CONSTRAINT mt_doc_issue_assignee_id_fkey FOREIGN KEY (assignee_id) | ||
REFERENCES public.mt_doc_user (id); | ||
|
||
CREATE INDEX mt_doc_issue_idx_assignee_id ON public.mt_doc_issue ("assignee_id"); | ||
``` | ||
|
||
And some other things you probably want to know about how this works internally: | ||
|
||
Marten is smart enough to order the "upsert" operations to make the dependent documents be updated last. | ||
In the `Issue` referencing `User` example above, this means that if you create a new `User` and a new | ||
`Issue` in the same session, when you call `IDocumentSession.SaveChanges()/SaveChangesAsync()`, Marten will know | ||
to save the new user first so that the issue will not fail with referential integrity violations. | ||
|
||
## Foreign Keys to non-Marten tables | ||
|
||
Marten can also create a foreign key to tables that are not managed by Marten. Continuing the our sample | ||
of `Issue`, we can create a foreign key from our `Issue` to our external bug tracking system: | ||
|
||
<!-- snippet: sample_configure-external-foreign-key --> | ||
<a id='snippet-sample_configure-external-foreign-key'></a> | ||
```cs | ||
var store = DocumentStore | ||
.For(_ => | ||
{ | ||
_.Connection("some database connection"); | ||
|
||
// Here we create a foreign key to table that is not | ||
// created or managed by marten | ||
_.Schema.For<Issue>().ForeignKey(i => i.BugId, "bugtracker", "bugs", "id"); | ||
}); | ||
``` | ||
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/Marten.Testing/Examples/ForeignKeyExamples.cs#L29-L39' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_configure-external-foreign-key' title='Start of snippet'>anchor</a></sup> | ||
<!-- endSnippet --> | ||
|
||
With the configuration above, Marten will generate a foreign key constraint from the `Issue` to a table in the | ||
`bug-tracker` schema called `bugs` on the `id` column. The constraint would be defined as: | ||
|
||
```sql | ||
ALTER TABLE public.mt_doc_issue | ||
ADD CONSTRAINT mt_doc_issue_bug_id_fkey FOREIGN KEY (bug_id) | ||
REFERENCES bug-tracker.bugs (id); | ||
``` | ||
|
||
## Cascading deletes | ||
|
||
Marten can also cascade deletes on the foreign keys that it creates. The `ForeignKeyDefinition` has a | ||
`CascadeDeletes` property that indicates whether the foreign key should enable cascading deletes. One way | ||
to enable this is to use a configuration function like: | ||
|
||
<!-- snippet: sample_cascade_deletes_with_config_func --> | ||
<a id='snippet-sample_cascade_deletes_with_config_func'></a> | ||
```cs | ||
var store = DocumentStore | ||
.For(_ => | ||
{ | ||
_.Connection("some database connection"); | ||
|
||
_.Schema.For<Issue>().ForeignKey<User>(x => x.AssigneeId, fkd => fkd.OnDelete = CascadeAction.Cascade); | ||
}); | ||
``` | ||
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/Marten.Testing/Examples/ForeignKeyExamples.cs#L44-L52' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_cascade_deletes_with_config_func' title='Start of snippet'>anchor</a></sup> | ||
<!-- endSnippet --> | ||
|
||
## Configuring with Attributes | ||
|
||
You can optionally configure properties or fields as foreign key relationships with the `[ForeignKey]` attribute: | ||
|
||
<!-- snippet: sample_issue-with-fk-attribute --> | ||
<a id='snippet-sample_issue-with-fk-attribute'></a> | ||
```cs | ||
public class Issue | ||
{ | ||
public Issue() | ||
{ | ||
Id = Guid.NewGuid(); | ||
} | ||
|
||
public Guid Id { get; set; } | ||
|
||
[ForeignKey(typeof(User))] | ||
public Guid UserId { get; set; } | ||
|
||
public Guid? OtherUserId { get; set; } | ||
} | ||
``` | ||
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/ForeignKeys/configuring_foreign_key_fields.cs#L68-L84' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_issue-with-fk-attribute' title='Start of snippet'>anchor</a></sup> | ||
<!-- endSnippet --> | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.