I am using Entity Framework using the POCO First approach. I pretty much followed the pattern described by Steve Sanderson in his book "Pro ASP.NET MVC 3 Framework", using the DI container and the DbContext class to connect to SQL Server.
The base tables on the SQL server contain very large datasets used by various applications. Because of this, I had to create views for the objects that I need in my application:
class RemoteServerContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<Contact> Contacts { get; set; }
...
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Customer>().ToTable("vw_Customers");
modelBuilder.Entity<Order>().ToTable("vw_Orders");
...
}
}
and it seems to work great for most of my needs.
The problem is that some of these views contain a lot of data in them, so when I call something like:
var customers = _repository.Customers().Where(c => c.Location == location).Where(...);
, , , LINQ , . , , SQL.
, ,
public IEnumerable<Customer> CustomersThatMatchACriteria(string criteria1, string criteria2, ...)
{
return Database.SqlQuery<Customer>("Exec pp_GetCustomersForCriteria @crit1 = {0}, @crit2 = {1}...", criteria1, criteria2,...);
}
, , DbSet, , . , , , "", DbSet.
- SQL- , ?