I'm having a bit of trouble getting my code to create a database using Entity Framework. Not sure how or why, but I think I'm missing something.
SecurityDataLayer.cs
namespace SecurityDoorDatabase.DBConnection
{
class SecurityDataLayer
{
public class SecurityDoorDBContext : DbContext
{
public DbSet<Person> Perons { get; set; }
public DbSet<Employee> Employees { get; set; }
public DbSet<Door> Doors { get; set; }
public DbSet<DoorSecurity> DoorSecurities { get; set; }
public DbSet<SecurityInput> SecurityInputs { get; set; }
public DbSet<SecurityLevel> SecurityLevels { get; set; }
public DbSet<SecurityCards> SecurityCard { get; set; }
public DbSet<FingerPrints> FingerPrint { get; set; }
}
}
}
Example of one of the many CS files I'm using.
class SecurityCards
{
int securityCardID;
int securityCardScan;
public int SecurityCardID { get => securityCardID; set => securityCardID = value; }
public int SecurityCardScan { get => securityCardScan; set => securityCardScan = value; }
public SecurityCards(int securityCardID, int securityCardScan)
{
SecurityCardID = securityCardID;
SecurityCardScan = securityCardScan;
}
}
The usings for every CS file.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data.Common;
using System.Collections.ObjectModel;
Program.CS
class Program
{
static void Main(string[] args)
{
Employee dingleberrySmith = new Employee(0, "Dingleberry", "Smithson", "Smith", 0, "IT Tech",
new FingerPrints(0,134), new SecurityCards(0,134), new SecurityLevel(4, 7));
Employee narsetSarkhan = new Employee(0, "Narset", "", "Sarkhan", 0, "Secretary",
new FingerPrints(0, 0), new SecurityCards(0, 0), new SecurityLevel(1, 1));
Door door597 = new Door(598, 597, "Fifth Floor", 598, 7, 7, "Door Code", "Security Card", "Finger Print");
Door door227 = new Door(228, 227, "Second Floor", 228, 2, 2, "Door Code", "Security Card", "Finger Print");
Door doorEntrance = new Door(0, 0, "Lobby", 0, 0, 0, "", "", "");
CanEmployeeGoThroughDoor(dingleberrySmith, door227);
CanEmployeeGoThroughDoor(dingleberrySmith, door597);
CanEmployeeGoThroughDoor(narsetSarkhan, door597);
CanEmployeeGoThroughDoor(narsetSarkhan, doorEntrance);
Console.ReadLine();
}
public static void CanEmployeeGoThroughDoor(Employee employee, Door door)
{
if ((employee.EmployeeSecurityLevel.SecurityLevelID >= door.SecurityLevelID) ||(employee.EmployeeSecurityLevel.SecurityLevelID >= door.SecurityLevelID && employee.EmployeeFingerPrint.FingerPrintScan > 0 && door.SecurityInputTertiary == "Finger Print" && employee.EmployeeSecurityCard.SecurityCardScan > 0 && door.SecurityInputSecondary == "Security Card") || (employee.EmployeeSecurityLevel.SecurityLevelID >= door.SecurityLevelID&& employee.EmployeeSecurityCard.SecurityCardScan > 0 && door.SecurityInputSecondary == "Security Card") || (employee.EmployeeSecurityLevel.SecurityLevelID >= door.SecurityLevelID && employee.EmployeeFingerPrint.FingerPrintScan > 0 && door.SecurityInputTertiary == "Finger Print"))
{
Console.WriteLine("Access Granted");
}
else
{
Console.WriteLine("Access Denied");
}
}
}
If someone could help me figure out how to make the database connections and where to put them, that'd be most appreciated.