Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
manoj-choudhari-git / ReferenceTypeDemo.cs
Created Aug 5, 2021
.NET - C# Features - Passing reference type by reference
View ReferenceTypeDemo.cs
// Pass Reference Type by Reference
public class ReferenceTypeDemo
{
public void Execute()
{
Person p = new Person();
p.Age = 25;
p.Name = "Sachin Tendulkar";
Console.WriteLine("----------------------------------------------------------------");
@manoj-choudhari-git
manoj-choudhari-git / ReferenceTypeDemo.cs
Created Aug 4, 2021
.NET - C# Features - An experiment with Reference Type Parameters
View ReferenceTypeDemo.cs
public class ReferenceTypeDemo
{
public void Execute()
{
Person p = new Person();
p.Age = 25;
p.Name = "Sachin Tendulkar";
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine($"Inside Caller: Before ChangeObject : Value: {p}");
@manoj-choudhari-git
manoj-choudhari-git / Program.cs
Last active Aug 4, 2021
.NET - C# Features - Pass reference type as parameter
View Program.cs
// Reference Type for Demo
public class Person
{
public int Age { get; set; }
public string Name { get; set; }
public override string ToString()
{
return $"{{ Age: {Age}, Name: {Name} }}";
}
@manoj-choudhari-git
manoj-choudhari-git / Program.cs
Created Aug 4, 2021
.NET - C# Features - Pass by value and Pass by reference for value types
View Program.cs
// ValueTypesDemo.cs
// PassByValue vs PassByReference
public class ValueTypeDemo
{
public void Execute()
{
int value = 9;
Console.WriteLine("----------------------------------------------------------------");
Console.WriteLine($"Inside Caller: Before ProcessByValue : Value: {value}");
@manoj-choudhari-git
manoj-choudhari-git / 20210722180825_InitialCreate.cs
Created Jul 23, 2021
.NET - Entity Framework Core - Migration File
View 20210722180825_InitialCreate.cs
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Students",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
@manoj-choudhari-git
manoj-choudhari-git / Program.cs
Last active Jul 23, 2021
.NET - Entity Framework Core - Global Query Filters Demo
View Program.cs
class Program
{
// Only Queries are shown below
// Rest of the methods are same as shown in previous snippet
static async Task DisplayStudentsByNationality(string nationality)
{
using var context = BuildUniversityContext();
var studentCollection = await context.Students
.Where(x => x.Nationality == nationality)
@manoj-choudhari-git
manoj-choudhari-git / UniversityContext.cs
Created Jul 22, 2021
.NET - Entity Framework Core - Global Filters Demo
View UniversityContext.cs
public class UniversityContext : DbContext
{
public UniversityContext(DbContextOptions<UniversityContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Student>().HasQueryFilter(s => !s.IsDeleted);
@manoj-choudhari-git
manoj-choudhari-git / Program.cs
Last active Jul 23, 2021
.NET - Entity Framework Core for demonstrating global query filters
View Program.cs
class Program
{
static async Task Main(string[] args)
{
// AddStudents();
await DisplayAllStudents();
await DisplayStudentsByNationality("Indian");
await DisplayStudentsByNationality("Australian");
await DisplayStudentsByNationality("British");
@manoj-choudhari-git
manoj-choudhari-git / Student.cs
Created Jul 22, 2021
.NET - Entity Framework Core - Student Entity for Global Filters Demo
View Student.cs
public class Student
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
@manoj-choudhari-git
manoj-choudhari-git / UniversityContext.cs
Created Jul 21, 2021
.NET - EF Core University Context with SQL Function
View UniversityContext.cs
public class UniversityContext : DbContext
{
public UniversityContext(DbContextOptions<UniversityContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var methodInfo = typeof(UniversityContext)