Skip to content

Instantly share code, notes, and snippets.

@RoyiNamir
Last active January 14, 2019 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RoyiNamir/3852b1af0a917b0cb8ad0ef09e62fc6a to your computer and use it in GitHub Desktop.
Save RoyiNamir/3852b1af0a917b0cb8ad0ef09e62fc6a to your computer and use it in GitHub Desktop.
1.cs
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
namespace ConsoleApp2.Models
{
public partial class MyContext : DbContext
{
public MyContext()
{
}
public MyContext(DbContextOptions<MyContext> options)
: base(options)
{
}
public virtual DbSet<Comments> Comments { get; set; }
public virtual DbSet<Images> Images { get; set; }
public virtual DbSet<Reports> Reports { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
optionsBuilder.UseSqlServer("Server=sff-pc;Database=IMG;Trusted_Connection=True;");
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasAnnotation("ProductVersion", "2.2.1-servicing-10028");
modelBuilder.Entity<Comments>(entity =>
{
entity.HasKey(e => e.CommentId);
entity.Property(e => e.CommentId).HasColumnName("CommentID");
entity.Property(e => e.CommentTxt)
.IsRequired()
.HasMaxLength(70);
entity.Property(e => e.DateCreated)
.HasColumnType("datetime")
.HasDefaultValueSql("(getutcdate())");
entity.Property(e => e.IsActive)
.IsRequired()
.HasDefaultValueSql("((1))");
});
modelBuilder.Entity<Images>(entity =>
{
entity.HasKey(e => e.ImageId);
entity.Property(e => e.Datecreated)
.HasColumnType("datetime")
.HasDefaultValueSql("(getutcdate())");
entity.Property(e => e.Description).HasMaxLength(70);
entity.Property(e => e.ImgExtension).HasMaxLength(400);
entity.Property(e => e.Ip)
.HasColumnName("IP")
.HasMaxLength(100)
.IsUnicode(false);
entity.Property(e => e.IsActive)
.IsRequired()
.HasDefaultValueSql("((1))");
entity.Property(e => e.Origin).HasMaxLength(4000);
entity.Property(e => e.Size)
.HasColumnName("size")
.HasColumnType("decimal(18, 2)");
});
modelBuilder.Entity<Reports>(entity =>
{
entity.HasKey(e => e.ReportId);
entity.Property(e => e.DateCreated)
.HasColumnType("datetime")
.HasDefaultValueSql("(getutcdate())");
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment