-
-
Save JohannesSundqvist/61ce36d34b0e6a86d704f852d4b756e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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