Skip to content

Commit 6a52218

Browse files
feat: Entity Framework Core YDB Quick Start
1 parent 30af596 commit 6a52218

File tree

6 files changed

+50
-22
lines changed

6 files changed

+50
-22
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ jobs:
195195
run: |
196196
cd ./examples/src/Topic
197197
dotnet run
198-
- name: Run EF example
198+
- name: Run Entity Framework Core example
199199
run: |
200-
cd ./examples/src/EF
200+
cd ./examples/src/EntityFrameworkCore.Ydb.QuickStart
201+
dotnet tool install --global dotnet-ef
202+
dotnet add package Microsoft.EntityFrameworkCore.Design
203+
dotnet ef migrations add InitialCreate
204+
dotnet ef database update
201205
dotnet run

examples/src/EF/EF.csproj

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<RootNamespace>EntityFrameworkCore.Ydb</RootNamespace>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\..\..\src\EFCore.Ydb\src\EntityFrameworkCore.Ydb.csproj" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.5">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
</ItemGroup>
21+
</Project>

examples/src/EF/Program.cs renamed to examples/src/EntityFrameworkCore.Ydb.QuickStart/Program.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,25 @@
33

44
await using var db = new BloggingContext();
55

6-
await db.Database.EnsureDeletedAsync();
7-
await db.Database.EnsureCreatedAsync();
8-
6+
// Create
97
Console.WriteLine("Inserting a new blog");
108
db.Add(new Blog { Url = "http://blogs.msdn.com/adonet" });
11-
129
await db.SaveChangesAsync();
1310

11+
// Read
1412
Console.WriteLine("Querying for a blog");
1513
var blog = await db.Blogs
1614
.OrderBy(b => b.BlogId)
1715
.FirstAsync();
1816

17+
// Update
1918
Console.WriteLine("Updating the blog and adding a post");
2019
blog.Url = "https://devblogs.microsoft.com/dotnet";
21-
blog.Posts.Add(new Post { Title = "Hello World", Content = "I wrote an app using EF Core!" });
20+
blog.Posts.Add(
21+
new Post { Title = "Hello World", Content = "I wrote an app using EF Core!" });
2222
await db.SaveChangesAsync();
2323

24+
// Delete
2425
Console.WriteLine("Delete the blog");
2526
db.Remove(blog);
2627
await db.SaveChangesAsync();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Entity Framework Core YDB Quick Start
2+
3+
A sample application from the [official documentation](https://learn.microsoft.com/en-us/ef/core/get-started/overview/first-app?tabs=netcore-cli)
4+
shows how to get started with EF, define a model, populate it with data and then query the database.
5+
6+
## Running QuickStart
7+
8+
1. Setup [YDB local](https://ydb.tech/docs/en/reference/docker/start).
9+
2. Create the database:
10+
```bash
11+
dotnet tool install --global dotnet-ef
12+
dotnet add package Microsoft.EntityFrameworkCore.Design
13+
dotnet ef migrations add InitialCreate
14+
dotnet ef database update
15+
```
16+
3. Run the app: `dotnet run`

examples/src/YdbExamples.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YC", "YC\YC.csproj", "{753E
1717
EndProject
1818
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Topic", "Topic\Topic.csproj", "{0FB9A1C2-4B0C-4AE4-9FA2-E0ED37802A6E}"
1919
EndProject
20-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EF", "EF\EF.csproj", "{0CE9DF93-1411-4E73-BA88-A66018FAB948}"
20+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCore.Ydb.QuickStart", "EntityFrameworkCore.Ydb.QuickStart\EntityFrameworkCore.Ydb.QuickStart.csproj", "{0CE9DF93-1411-4E73-BA88-A66018FAB948}"
2121
EndProject
2222
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCore.Ydb.Yandex.Cloud", "EntityFrameworkCore.Ydb.Yandex.Cloud\EntityFrameworkCore.Ydb.Yandex.Cloud.csproj", "{8F7266C7-75BB-4753-9FB2-BDF4678AF73B}"
2323
EndProject

0 commit comments

Comments
 (0)