-
-
Save JohannesSundqvist/5fbf2eef062371da3c2dd17c5fcc888c 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 Customer | |
{ | |
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 DataContext : DbContext | |
{ | |
public DataContext(DbContextOptions<DataContext> options) | |
: base(options) | |
{ | |
} | |
public DbSet<User> Users { get; set; } | |
public DbSet<Customer> Customers { get; set; } | |
public User GetUserData() | |
{ | |
var query = (from a in Users | |
where a != null | |
select a).FirstOrDefault(); | |
return query; | |
} | |
} |
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 interface IDataContext | |
{ | |
User GetUserData(); | |
} |
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 IDataContext _context; | |
public IActionResult MainPage() | |
{ | |
var usernameQuery = _context.GetUserData(); | |
ViewData["DisplayUsername"] = usernameQuery; | |
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
public class User | |
{ | |
public string Username { get; set; } | |
public string Password { 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
<connectionStrings> | |
<add name="DataContext" | |
providerName="System.Data.EntityClient" | |
connectionString="Data Source=[SERVER-NAME];Initial Catalog=[TABLE-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