Skip to content

Instantly share code, notes, and snippets.

@JohannesSundqvist
Created September 1, 2016 06:18
Show Gist options
  • Save JohannesSundqvist/22b6bb4446891d22aeb40aaa9f50c580 to your computer and use it in GitHub Desktop.
Save JohannesSundqvist/22b6bb4446891d22aeb40aaa9f50c580 to your computer and use it in GitHub Desktop.
public class DataContext : DbContext, IDataContext
{
public DbSet<Customer> Customers { get; set; }
public Customer FetchTableData()
{
var query = (from a in Customers
where a != null
select a).FirstOrDefault();
return query;
}
}
public interface IDataContext
{
Customer FetchTableData();
}
private IDataContext _context;
public MainController(IDataContext context)
{
_context = context;
}
public IActionResult MainPage()
{
var getData = _context.FetchTableData().Name;
ViewData["DisplayName"] = getData;
return View();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment