added metadata, about and some post navigation
This commit is contained in:
parent
f9de954724
commit
59c253b296
29 changed files with 85 additions and 32 deletions
|
|
@ -4,12 +4,14 @@ author: dreat
|
|||
layout: post
|
||||
published: true
|
||||
post_date: 2017-06-23 21:22:01
|
||||
tags: [archived]
|
||||
tags: [archived, til, csharp]
|
||||
categories: [til, theory, old_blog]
|
||||
---
|
||||
While using EntityFramework in my integration tests (which is a separate topic ;) ) I discovered quite interesting thing. I guess this may be obvious to some, but I learned Entity "the hard way" jumping into an app with Entity already in place and had to adapt - this was my first app with a database by the way.
|
||||
|
||||
So if you add entities to your context I'm used to adding all entities to context, so the code would look like
|
||||
[csharp]
|
||||
|
||||
```csharp
|
||||
using (var ctx = new Context())
|
||||
{
|
||||
var first = new FirstEntity { .. };
|
||||
|
|
@ -19,10 +21,11 @@ using (var ctx = new Context())
|
|||
ctx.SecondEntities.Add(second);
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
[/csharp]
|
||||
```
|
||||
|
||||
But if entities are related, you can safely do this
|
||||
[csharp]
|
||||
|
||||
```csharp
|
||||
using (var ctx = new Context())
|
||||
{
|
||||
var first = new FirstEntity { .. };
|
||||
|
|
@ -32,9 +35,12 @@ using (var ctx = new Context())
|
|||
ctx.SecondEntities.Add(second);
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
[/csharp]
|
||||
```
|
||||
|
||||
|
||||
Or even this!
|
||||
[csharp]
|
||||
|
||||
```csharp
|
||||
using (var ctx = new Context())
|
||||
{
|
||||
var second = new SecondEntity { Relation = new FirstEntity{ .. } };
|
||||
|
|
@ -42,6 +48,6 @@ using (var ctx = new Context())
|
|||
ctx.SecondEntities.Add(second);
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
[/csharp]
|
||||
```
|
||||
|
||||
It's nice and saves some typing! :)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue