简单地从Oracle DB获取数据时实体框架抛出异常

时间:2018-02-21 19:57:01

标签: c# oracle entity-framework

我有以下类和接口,基本上试图通过实体框架从Oracle db进行简单的get调用。 但是在GetEntities()方法中获取与MoveNext()迭代相关的异常, _customersEntities 在运行时变为null。

 public interface IServiceDelegatesCustomerRepository
    {
        List<CustomersDto> GetEntities();
    }
 public class ServiceDelegatesCustomerRepository : IServiceDelegatesCustomerRepository
            {
private readonly CustomerEntities _customersEntities;
//Constructor here CustomerEntities is from DbContext Class
public ServiceDelegatesCustomerRepository(CustomerEntities customersEntities)
        {
            _customersEntities = customersEntities;

        }
public List<CustomersDto> GetEntities()
                {
                    try
                    {
                        return  _customersEntities.Customers.Select(x => new CustomersDto
                        {
                            CustomerId = x.CustomerId,
                            CustomerFirstName = x.CustomerFirstName,
                            CustomerMiddleName = x.CustomerMiddleName,
                            CustomerLastName = x.CustomerLastName,
                            CustomerType = x.CustomerType,
                            CustomerTitle = x.CustomerTitle
                        }).ToList();
                    }
                    catch (Exception ex)
                    {
                        //_log.Error($"Unexpected error occurred while extracting the list of customers", ex);
                        Console.Write(ex.InnerException);
                        throw;
                    }
                }
        }

现在CustomersDto看起来像:

public class CustomersDto
    {
        public decimal CustomerId { get; set; }

        public string CustomerType { get; set; }

        public string CustomerTitle { get; set; }

        public string CustomerFirstName { get; set; }

        public string CustomerMiddleName { get; set; }

        public string CustomerLastName { get; set; }

    }

0 个答案:

没有答案