admin管理员组

文章数量:1410674

I´m having problems with the next error

Stack Trace:

Exception type: InvalidCastException 
   Exception message: The specified conversion is not valid.
  on System.Data.SqlClient.SqlBuffer.get_DateTime()
  on System.Data.SqlClient.SqlDataReader.GetDateTime(Int32 i)
  on Read_Table_Zona(ObjectMaterializer`1 )
  on System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext()
  on System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
  on System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
  on ...ReporteDA.GetZona()

I generated my database scheme from Server Explorer update it from the production env, but while it's on production sometimes this error appears and throws the site

Code:

public static List<Table_Zona> GetZona()
{
    dc = new DBDataContext();
    var list = dc.Table_Zona.ToList();
    return list;
}

DBDataContext:

public DBDataContext() :
        base(global::System.Configuration.ConfigurationManager.ConnectionStrings["BD_RConnectionString"].ConnectionString, mappingSource)
{
    OnCreated();
}

Table_Zona:

[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Table_Zona")]
public partial class Table_Zona : INotifyPropertyChanging, INotifyPropertyChanged
{
        
    private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
        
    private int _id;
        
    private string _Zona;
        
    private string _Descripcion;
        
    private System.Nullable<System.DateTime> _fListaContador;
        
    private System.Nullable<System.DateTime> _fListaAsesor;
        
    private string _TableName;
        
    private EntitySet<Table_Agencia> _Table_Agencias;
    // ...
}

Database:

CREATE TABLE [dbo].[Table_Zona](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [Zona] [varchar](20) NOT NULL,
    [Descripcion] [varchar](50) NULL,
    [fListaContador] [datetime] NULL,
    [fListaAsesor] [datetime] NULL,
    [TableName] [nvarchar](150) NULL
)
id Zona Descripcion fListaContador fListaAsesor TableName
1 Zona A Zona A NULL NULL Table_ReportesZA
2 Zona B Zona B NULL NULL Table_Reportes

本文标签: cInvalidCastException getDateTime() on SystemDataLinqStack Overflow