-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sample groupby issue query in ef 3.1
- Loading branch information
1 parent
250df9a
commit 124467e
Showing
10 changed files
with
562 additions
and
4 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
73 changes: 73 additions & 0 deletions
73
QueryingIssues.EF3.1/Migrations/20231103163846_Init.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
namespace QueryingIssues.EF3._1.Migrations | ||
{ | ||
public partial class Init : Migration | ||
{ | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.CreateTable( | ||
name: "Blogs", | ||
columns: table => new | ||
{ | ||
BlogId = table.Column<int>(nullable: false) | ||
.Annotation("Sqlite:Autoincrement", true), | ||
Url = table.Column<string>(nullable: true) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Blogs", x => x.BlogId); | ||
}); | ||
|
||
migrationBuilder.CreateTable( | ||
name: "Posts", | ||
columns: table => new | ||
{ | ||
PostId = table.Column<int>(nullable: false) | ||
.Annotation("Sqlite:Autoincrement", true), | ||
Title = table.Column<string>(nullable: true), | ||
Content = table.Column<string>(nullable: true), | ||
BlogId = table.Column<int>(nullable: false), | ||
CreatedAt = table.Column<DateTime>(nullable: false), | ||
NumberOfView = table.Column<long>(nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Posts", x => x.PostId); | ||
table.ForeignKey( | ||
name: "FK_Posts_Blogs_BlogId", | ||
column: x => x.BlogId, | ||
principalTable: "Blogs", | ||
principalColumn: "BlogId", | ||
onDelete: ReferentialAction.Cascade); | ||
}); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_Posts_BlogId", | ||
table: "Posts", | ||
column: "BlogId"); | ||
} | ||
|
||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "Posts"); | ||
|
||
migrationBuilder.DropTable( | ||
name: "Blogs"); | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
QueryingIssues.EF3.1/Migrations/BloggingContextModelSnapshot.cs
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// <auto-generated /> | ||
using System; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | ||
|
||
namespace QueryingIssues.EF3._1.Migrations | ||
{ | ||
[DbContext(typeof(BloggingContext))] | ||
partial class BloggingContextModelSnapshot : ModelSnapshot | ||
{ | ||
protected override void BuildModel(ModelBuilder modelBuilder) | ||
{ | ||
#pragma warning disable 612, 618 | ||
modelBuilder | ||
.HasAnnotation("ProductVersion", "3.1.32"); | ||
|
||
modelBuilder.Entity("Blog", b => | ||
{ | ||
b.Property<int>("BlogId") | ||
.ValueGeneratedOnAdd() | ||
.HasColumnType("INTEGER"); | ||
|
||
b.Property<string>("Url") | ||
.HasColumnType("TEXT"); | ||
|
||
b.HasKey("BlogId"); | ||
|
||
b.ToTable("Blogs"); | ||
}); | ||
|
||
modelBuilder.Entity("Post", b => | ||
{ | ||
b.Property<int>("PostId") | ||
.ValueGeneratedOnAdd() | ||
.HasColumnType("INTEGER"); | ||
|
||
b.Property<int>("BlogId") | ||
.HasColumnType("INTEGER"); | ||
|
||
b.Property<string>("Content") | ||
.HasColumnType("TEXT"); | ||
|
||
b.Property<DateTime>("CreatedAt") | ||
.HasColumnType("TEXT"); | ||
|
||
b.Property<long>("NumberOfView") | ||
.HasColumnType("INTEGER"); | ||
|
||
b.Property<string>("Title") | ||
.HasColumnType("TEXT"); | ||
|
||
b.HasKey("PostId"); | ||
|
||
b.HasIndex("BlogId"); | ||
|
||
b.ToTable("Posts"); | ||
}); | ||
|
||
modelBuilder.Entity("Post", b => | ||
{ | ||
b.HasOne("Blog", "Blog") | ||
.WithMany("Posts") | ||
.HasForeignKey("BlogId") | ||
.OnDelete(DeleteBehavior.Cascade) | ||
.IsRequired(); | ||
}); | ||
#pragma warning restore 612, 618 | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.Logging; | ||
|
||
public class BloggingContext : DbContext | ||
{ | ||
public static readonly ILoggerFactory MyLoggerFactory | ||
= LoggerFactory.Create(builder => builder.AddConsole()); | ||
|
||
public DbSet<Blog> Blogs { get; set; } | ||
public DbSet<Post> Posts { get; set; } | ||
|
||
public string DbPath { get; } | ||
|
||
public BloggingContext() | ||
{ | ||
var folder = Environment.SpecialFolder.LocalApplicationData; | ||
var path = Environment.GetFolderPath(folder); | ||
DbPath = System.IO.Path.Join(path, "blogging3.1.db"); | ||
} | ||
|
||
// The following configures EF to create a Sqlite database file in the | ||
// special "local" folder for your platform. | ||
protected override void OnConfiguring(DbContextOptionsBuilder options) | ||
=> options | ||
.UseLoggerFactory(MyLoggerFactory) // Enable EF Core logging | ||
// .UseSqlServer( | ||
// "Server=LAPTOP-IAJ1J0A2;Database=blogpost;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=true"); | ||
.UseSqlite($"Data Source={DbPath}"); | ||
} | ||
|
||
public class Blog | ||
{ | ||
public int BlogId { get; set; } | ||
public string Url { get; set; } | ||
|
||
public List<Post> Posts { get; } = new List<Post>(); | ||
} | ||
|
||
public class Post | ||
{ | ||
public int PostId { get; set; } | ||
public string Title { get; set; } | ||
public string Content { get; set; } | ||
|
||
public int BlogId { get; set; } | ||
public Blog Blog { get; set; } | ||
public DateTime CreatedAt { get; set; } | ||
|
||
public long NumberOfView { get; set; } | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
|
||
namespace QueryingIssues.EF3._1 | ||
{ | ||
public class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var query5 = new QueryStackoverflowGroupBy(); | ||
query5.QueryNo59456026(); | ||
query5.QueryNo59456026_Workaround(); | ||
} | ||
} | ||
} |
Oops, something went wrong.