I am developing a Human Resources System, where I have used EntityFrameworks, get to the part that I need to create Tables through the application and be able to use them later. Can You Create Tabas Dynamically with EF? What would be the Code?
I am developing a Human Resources System, where I have used EntityFrameworks, get to the part that I need to create Tables through the application and be able to use them later. Can You Create Tabas Dynamically with EF? What would be the Code?
web application
use the templates of Web API
and MVC
if you want to work with REST
, if you only want to make a website with a Bootstrap template, select only MVC
For example
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace TutorialEntityFramework.Models
{
public class BlogPost
{
public int Id { get; set; }
[Required]
[StringLength(200)]
public string Titulo { get; set; }
[Required]
public string Contenido { get; set; }
[StringLength(100)]
public string Autor { get; set; }
public DateTime Publicacion { get; set; }
}
}
DbContext
Example
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace TutorialEntityFramework.Models
{
public class BlogContext: DbContext
{
public BlogContext()
: base("DefaultConnection")
{
}
public DbSet BlogPosts { get; set; }
}
}
enable-migrations
migrations
folder, open the file configuration.cs
update-database
command
PS: You're supposed to have your connectionString
set in your web.config
before doing all that
Example
<connectionStrings>
<add name="DefaultConnection" connectionString="data source=TU_SERVIDOR;initial catalog=NOMBRE_DE_BD;integrated security=false;persist security info=True;User ID=TU_NOMBRE_DE_USUARIO;Password=TU_CLAVE_DE_BD" providerName="System.Data.SqlClient"/>
</connectionStrings>