Skip to content

Instantly share code, notes, and snippets.

@JohannesSundqvist
Created August 25, 2016 10:25
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 JohannesSundqvist/61ce36d34b0e6a86d704f852d4b756e4 to your computer and use it in GitHub Desktop.
Save JohannesSundqvist/61ce36d34b0e6a86d704f852d4b756e4 to your computer and use it in GitHub Desktop.
public class DataContext : DbContext
{
public DataContext(DbContextOptions<DataContext> options)
: base(options)
{
}
public DbSet<Users> User { get; set; }
public DbSet<Customers> Customer { get; set; }
public class Users
{
public string Username { get; set; }
public string Password { get; set; }
}
public class Customers
{
public string Name { get; set; }
public string PhoneNumber { get; set; }
public string Email { get; set; }
}
}
public class MainController : Controller
{
private DataContext _context;
public MainController(DataContext context)
{
_context = context;
}
public IActionResult MainPage(string username)
{
var query = (from u in _context.User
where u != null
select u).ToList();
ViewData["DisplayUsername"] = query;
return View();
}
}
<connectionStrings>
<add name="DataContext"
providerName="System.Data.EntityClient"
connectionString="Data Source=[SERVER-NAME];Initial Catalog=[DATABASE-NAME];Integrated Security=True;MultipleActiveResultSets=True;user id=[USERNAME];password=[PASSWORD];"/>
</connectionStrings>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment