I am implementing a web api that will retrieve data using the framework 6 entity. I use Sql Server 2014 and visual studio 2015. If I debug the code in the CustomerDao class, I see an exception in the customerOrderContext object, although I can see the entries in the client object. However, after executing the use block, I do not see any entries.
((System.Data.SqlClient.SqlConnection) customerOrderContext.Database.Connection) .ServerVersion
CustomerDAO
using (var customerOrderContext = new Entities()) { return (from customer in customerOrderContext.Customers select new CustomerOrder.BusinessObjects.Customers { Id = customer.Id, FirstName = customer.FirstName, LastName = customer.LastName, Address = customer.Address, City = customer.City, Email = customer.Email, Gender = customer.Gender, State = customer.State, Zip = customer.Zip }).ToList(); }
The connection string in the configuration file is as follows
<add name="Entities" connectionString="metadata=res://*/EF.CustomerOrderContext.csdl|res://*/EF.CustomerOrderContext.ssdl|res://*/EF.CustomerOrderContext.msl;provider=System.Data.SqlClient;provider connection string="data source=Tom-PC\MSSQLSERVER2014;initial catalog=Ransang;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Context class follows
public partial class Entities : DbContext { public Entities() : base("name=Entities") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { } public virtual DbSet<Customer> Customers { get; set; } public virtual DbSet<OrderDetail> OrderDetails { get; set; } public virtual DbSet<Order> Orders { get; set; } public virtual DbSet<Product> Products { get; set; } }
CustomProvider.cs
public IEnumerable<BusinessObjects.Customers> GetAllCustomers() { IList<BusinessObjects.Customers> customerCollection = new List<BusinessObjects.Customers>(); dataAccess.CustomerDao.GetAllCustomers(); return customerCollection; }
source share