Entity Framework CRUD in .NET core | Bsc CSIT 6th sem | Net Centric Computing | .NET Framework

Поделиться
HTML-код
  • Опубликовано: 8 сен 2024
  • Entity Framework CRUD in .NET core
    CSIT 6th sem
    Net centric computing
    dotnet core Entity Framework CRUD
    CSharp
    c#
    Source code: github.com/diw...

Комментарии • 19

  • @dahaldiwash2
    @dahaldiwash2  2 года назад +2

    Source code: github.com/diwash007/CSIT-6th-sem-NCC-codes/blob/main/console%20app%20with%20EF%20CRUD/Program.cs

  • @JukeBoxNepalAndLyrics
    @JukeBoxNepalAndLyrics 2 года назад +2

    Kada 😍😍

  • @kritstims
    @kritstims 2 года назад +2

    You're a life saviour . Big fan sir 🙌😂

  • @nirajpdn
    @nirajpdn 2 года назад +2

    Nice

  • @adeshpokhrel15
    @adeshpokhrel15 2 года назад +2

    Kada

  • @mrdhimal1999
    @mrdhimal1999 3 месяца назад +1

    15:08
    Plz do solve the question of CSIT 2080 or send me the code.
    Q. Create a table named BAG(ID, Brand, Price, Date). Perform the following operations using Entity Framework core.
    a. Update the price of those Book to 2000 which are published on 2022.
    b. DELETE the book which are published in 1981.
    c. Retrieve the Brand of Book having price greater than 500.

    • @dahaldiwash2
      @dahaldiwash2  2 месяца назад

      Here you go:
      using Microsoft.EntityFrameworkCore;
      using System.ComponentModel.DataAnnotations;
      using System.ComponentModel.DataAnnotations.Schema;
      public class Bag {
      [Key]
      public int ID {get; set;}
      [Column(TypeName = "varchar(200)")]
      public string Brand {get; set;}
      public int Price {get; set;}
      public DateTime Date { get; set; }
      }
      public class DataContext : DbContext {
      protected override void OnConfiguring(DbContextOptionsBuilder ob) {
      ob.UseMySQL("server=localhost;database=csit;user=root;password=;");
      }
      public DbSet bags {get; set;}
      }
      public class Program {
      DataContext dc = new DataContext();
      public void Insert(Bag b) {
      dc.bags.Add(b);
      dc.SaveChanges();
      }
      public void Delete(int id) {
      var bag = dc.bags.Find(id);
      if (bag == null) return;
      dc.bags.Remove(bag);
      dc.SaveChanges();
      }
      public void Read() {
      foreach(var s in dc.bags) {
      Console.WriteLine($"Name: {s.Name}");
      }
      }
      public void Update(int id, Bag s) {
      Bag bag = dc.bags.Find(id);
      if (bag == null) return;
      bag.Brand = s.Brand;
      bag.Date = s.Date;
      bag.Price = s.Price;
      dc.bags.Update(bag);
      dc.SaveChanges();
      }
      public static void Main()
      {
      DataContext dc = new DataContext();
      // Update the price of those Bags to 2000 which are published in 2022
      var bags2022 = dc.bags.Where(b => b.Date.Year == 2022).ToList();
      foreach (var bag in bags2022)
      {
      bag.Price = 2000;
      }
      dc.SaveChanges();
      Console.WriteLine("Updated the price of bags published in 2022 to 2000.");
      // DELETE the bags which are published in 1981
      var bags1981 = dc.bags.Where(b => b.Date.Year == 1981).ToList();
      foreach (var bag in bags1981)
      {
      dc.bags.Remove(bag);
      }
      dc.SaveChanges();
      Console.WriteLine("Deleted the bags published in 1981.");
      // Retrieve the Brand of Bags having price greater than 500
      var expensiveBags = dc.bags.Where(b => b.Price > 500).Select(b => b.Brand).ToList();
      Console.WriteLine("Brands of bags with price greater than 500:");
      foreach (var brand in expensiveBags)
      {
      Console.WriteLine(brand);
      }
      }
      }

  • @peshaloli9122
    @peshaloli9122 2 года назад +2

    All is well

  • @arunbasnet5423
    @arunbasnet5423 2 года назад +2

    data diyera insert gaar vanyo vaney(like 2078)........hamile mathi insert method matra banauda hunxa ?? ki update ,delete,read ni parxa?

    • @dahaldiwash2
      @dahaldiwash2  2 года назад

      insert mattai gar vanyo vane ta .. insert mattai banauda vaihaalyo ni

  • @anirbansensharma
    @anirbansensharma Год назад +1

    I can say that the hack works fine

  • @samipupreti1588
    @samipupreti1588 2 года назад +2

    Kada