In a C# 2008 web application, I have the following statement that give when an error when the code points to a different database: eRPTDataContext rptDataaddRVW = new eRPTDataContext(); var eRPTaddRVW = (from a in rptDataaddRVW.eRPT_Transaction_Trackings
where a.Package_ID == packageId select a).FirstOrDefault();
Here is the error message I get: 2013-02-04 16:13:15.3731|ERROR|erptsampleclient.eRPTSample|Error Processing --> Specified cast is not valid. 2013-02-04 16:13:15.3731|ERROR|erptsampleclient.eRPTSample|************* Stack Trace ******************* 2013-02-04
16:13:15.3887|ERROR|erptsampleclient.eRPTSample| at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression
query) at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression) at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source) at erptsampleclient.eRPTSample.addNewReviewPackage() in C:\_svn\Cas_client\erptsampleclient\eRPTSample.cs:line
1308 2013-02-04 16:13:15.3887|ERROR|erptsampleclient.eRPTSample|Error Processing --> Specified cast is not valid. 2013-02-04 16:13:15.3887|ERROR|erptsampleclient.eRPTSample|************* Stack Trace ******************* 2013-02-04 16:13:15.4043|ERROR|erptsampleclient.eRPTSample|
at erptsampleclient.eRPTSample.addNewReviewPackage() in C:\_svn\Cas_client\erptsampleclient\eRPTSample.cs:line 1369 at erptsampleclient.eRPTSample.Main(String[] args) in C:\_svn\Cas_client\erptsampleclient\eRPTSample.cs:line 154 2013-02-04 16:13:23.3135|INFO|erptsampleclient.eRPTSample|******************ADD
(CREATE) REVIEW (RVW) (METHOD 2 CALL)********************** 2013-02-04 16:13:28.8359|INFO|erptsample.ERPTProxy|The number of attachments in the list are ->1 2013-02-04 16:13:54.2171|INFO|erptsample.ERPTProxy|add review package successfully for rvw pkg id:
RVW0204201300524 return code = 0 2013-02-04 16:13:58.5227|INFO|erptsampleclient.eRPTSample|Review Package was created successfully for Package id: RVW0204201300524 2013-02-04 16:13:58.5695|ERROR|erptsampleclient.eRPTSample|Error Processing --> Specified cast
is not valid. 2013-02-04 16:13:58.5695|ERROR|erptsampleclient.eRPTSample|************* Stack Trace ******************* 2013-02-04 16:13:58.5851|ERROR|erptsampleclient.eRPTSample| at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo
queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult) at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory,
Object[] userArguments, ICompiledSubQuery[] subQueries) at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source) When I change the code to the following: var eRPTaddRVW = (from a in rptDataaddRVW.eRPT_Transaction_Trackings
where a.Package_ID == packageId select new { erptPackageID = a.Package_ID, erptFileLocation = a.File_Location }).FirstOrDefault();
I do not get an error. The problem is I want to be able to update the database row I just accessed and the linq will not compile clean to let me do that.
I am getting the follwowing error message when I try to access a specific field: Error 10 'object' does not contain a definition for 'erptFileLocation' and no extension method 'erptFileLocation' accepting a first argument of type 'object' could be found
(are you missing a using directive or an assembly reference?) C:\_svn\Cas_client\erptsampleclient\eRPTSample.cs 1320 56 ERPTsampleclient Here is the code I am trying to add: if (eRPTaddRVW != null) { eRPTaddRVW.erptFileLocation = RVWFile;
// save location of original spreadshgeet rptDataaddRVW.SubmitChanges(); }
Can you tell me what I can do to solve my problem?
The error that is being thrown is an invalid casting error. You are most likely trying to store an object in your database that doesn't match the type of object that the database is expecting.
Can you post any additional code that could be possibly related to this area?
eRPTDataContext rptDataaddRVW = new eRPTDataContext();
//This grabs a single "Transaction Tracking" object
var eRPTaddRVW = (from a in rptDataaddRVW.eRPT_Transaction_Trackings
where a.Package_ID == packageId
select a).FirstOrDefault();
if (eRPTaddRVW != null)
{
eRPTaddRVW.erptFileLocation = RVWFile;
rptDataaddRVW.SubmitChanges();
}
You mentioned recieving an "object does not contain a definition..." error the erptFileLocation property of your eRTPaddRVW object (that you recieved from your query). Are you sure that you are querying the correct database?
I have the following items I would like to mention:
1. Here is some of the additional code you suggested I post:
string[] names = fileName.Split('_');
strorgnizationName = names[0].TrimEnd();
contactName = names[1].TrimStart();
CMS_DW_eRPTDataContext cms_eRPTData = new CMS_DW_eRPTDataContext();
var eRPTContractNumber = (from cms_dw in cms_eRPTData.EDV_CONTACTs
join d in cms_eRPTData.MARX_UI_DETAIL_SAMPLE_TOTALs on cms_dw.CONTRACT_NUMBER equals d.CONTRACT_NUMBER
where cms_dw.Organization_Name.ToUpper().Trim() == strOrgnizationName.Trim() &&
cms_dw.Contact_First_Last_Name.ToUpper().Trim() == contactName.Trim()
select cms_dw.CONTRACT_NUMBER).FirstOrDefault();
packageId = proxy.addPackage(pkgDetails, pkgDocsList, ist);
eRPTDataContext rptDataaddRVW = new eRPTDataContext();
var eRPTaddRVW = (from a in rptDataaddRVW.eRPT_Transaction_Trackings
where a.Package_ID == packageId
select a).FirstOrDefault();
2. The table I am querying now has 3 triggers on it. Do I need to drag theese triggers onto the viusal designer? If so, can you give directions on how to drag triggers on to the designer?
3. Is there another object type besides 'var' that I can use for the query I have listed above? If there is another type I can use besides 'var' that would work, can you tell me what the var would be replaced withg?
Do I need to drag theese triggers onto the viusal designer? If so, can you give directions on how to drag triggers on to the designer?
No. Triggers will be fired only automatically when CRUD (Insert/Delete/Update) happens. You can never drag and drop them onto dbml file to create methods.
wendy elizabeth
Is there another object type besides 'var' that I can use for the query I have listed above?
"var" will automatically recognize your returned value's type. You don't need to change that.
wendy elizab...
Member
321 Points
390 Posts
C# linq to sql error
Feb 04, 2013 10:27 PM|LINK
In a C# 2008 web application, I have the following statement that give when an error when the code points to a different database: eRPTDataContext rptDataaddRVW = new eRPTDataContext(); var eRPTaddRVW = (from a in rptDataaddRVW.eRPT_Transaction_Trackings where a.Package_ID == packageId select a).FirstOrDefault();
Here is the error message I get: 2013-02-04 16:13:15.3731|ERROR|erptsampleclient.eRPTSample|Error Processing --> Specified cast is not valid. 2013-02-04 16:13:15.3731|ERROR|erptsampleclient.eRPTSample|************* Stack Trace ******************* 2013-02-04 16:13:15.3887|ERROR|erptsampleclient.eRPTSample| at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult) at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression) at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source) at erptsampleclient.eRPTSample.addNewReviewPackage() in C:\_svn\Cas_client\erptsampleclient\eRPTSample.cs:line 1308 2013-02-04 16:13:15.3887|ERROR|erptsampleclient.eRPTSample|Error Processing --> Specified cast is not valid. 2013-02-04 16:13:15.3887|ERROR|erptsampleclient.eRPTSample|************* Stack Trace ******************* 2013-02-04 16:13:15.4043|ERROR|erptsampleclient.eRPTSample| at erptsampleclient.eRPTSample.addNewReviewPackage() in C:\_svn\Cas_client\erptsampleclient\eRPTSample.cs:line 1369 at erptsampleclient.eRPTSample.Main(String[] args) in C:\_svn\Cas_client\erptsampleclient\eRPTSample.cs:line 154 2013-02-04 16:13:23.3135|INFO|erptsampleclient.eRPTSample|******************ADD (CREATE) REVIEW (RVW) (METHOD 2 CALL)********************** 2013-02-04 16:13:28.8359|INFO|erptsample.ERPTProxy|The number of attachments in the list are ->1 2013-02-04 16:13:54.2171|INFO|erptsample.ERPTProxy|add review package successfully for rvw pkg id: RVW0204201300524 return code = 0 2013-02-04 16:13:58.5227|INFO|erptsampleclient.eRPTSample|Review Package was created successfully for Package id: RVW0204201300524 2013-02-04 16:13:58.5695|ERROR|erptsampleclient.eRPTSample|Error Processing --> Specified cast is not valid. 2013-02-04 16:13:58.5695|ERROR|erptsampleclient.eRPTSample|************* Stack Trace ******************* 2013-02-04 16:13:58.5851|ERROR|erptsampleclient.eRPTSample| at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult) at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression) at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source) When I change the code to the following: var eRPTaddRVW = (from a in rptDataaddRVW.eRPT_Transaction_Trackings where a.Package_ID == packageId select new { erptPackageID = a.Package_ID, erptFileLocation = a.File_Location }).FirstOrDefault();
I do not get an error. The problem is I want to be able to update the database row I just accessed and the linq will not compile clean to let me do that.
I am getting the follwowing error message when I try to access a specific field: Error 10 'object' does not contain a definition for 'erptFileLocation' and no extension method 'erptFileLocation' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) C:\_svn\Cas_client\erptsampleclient\eRPTSample.cs 1320 56 ERPTsampleclient Here is the code I am trying to add: if (eRPTaddRVW != null) { eRPTaddRVW.erptFileLocation = RVWFile; // save location of original spreadshgeet rptDataaddRVW.SubmitChanges(); }
Can you tell me what I can do to solve my problem?
Rion William...
All-Star
27906 Points
4618 Posts
Re: C# linq to sql error
Feb 04, 2013 11:21 PM|LINK
The error that is being thrown is an invalid casting error. You are most likely trying to store an object in your database that doesn't match the type of object that the database is expecting.
Can you post any additional code that could be possibly related to this area?
eRPTDataContext rptDataaddRVW = new eRPTDataContext(); //This grabs a single "Transaction Tracking" object var eRPTaddRVW = (from a in rptDataaddRVW.eRPT_Transaction_Trackings where a.Package_ID == packageId select a).FirstOrDefault(); if (eRPTaddRVW != null) { eRPTaddRVW.erptFileLocation = RVWFile; rptDataaddRVW.SubmitChanges(); }You mentioned recieving an "object does not contain a definition..." error the erptFileLocation property of your eRTPaddRVW object (that you recieved from your query). Are you sure that you are querying the correct database?
wendy elizab...
Member
321 Points
390 Posts
Re: C# linq to sql error
Feb 05, 2013 02:13 AM|LINK
I have the following items I would like to mention:
1. Here is some of the additional code you suggested I post:
string[] names = fileName.Split('_'); strorgnizationName = names[0].TrimEnd(); contactName = names[1].TrimStart(); CMS_DW_eRPTDataContext cms_eRPTData = new CMS_DW_eRPTDataContext(); var eRPTContractNumber = (from cms_dw in cms_eRPTData.EDV_CONTACTs join d in cms_eRPTData.MARX_UI_DETAIL_SAMPLE_TOTALs on cms_dw.CONTRACT_NUMBER equals d.CONTRACT_NUMBER where cms_dw.Organization_Name.ToUpper().Trim() == strOrgnizationName.Trim() && cms_dw.Contact_First_Last_Name.ToUpper().Trim() == contactName.Trim() select cms_dw.CONTRACT_NUMBER).FirstOrDefault(); packageId = proxy.addPackage(pkgDetails, pkgDocsList, ist); eRPTDataContext rptDataaddRVW = new eRPTDataContext(); var eRPTaddRVW = (from a in rptDataaddRVW.eRPT_Transaction_Trackings where a.Package_ID == packageId select a).FirstOrDefault();2. The table I am querying now has 3 triggers on it. Do I need to drag theese triggers onto the viusal designer? If so, can you give directions on how to drag triggers on to the designer?
3. Is there another object type besides 'var' that I can use for the query I have listed above? If there is another type I can use besides 'var' that would work, can you tell me what the var would be replaced withg?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: C# linq to sql error
Feb 06, 2013 12:47 AM|LINK
No. Triggers will be fired only automatically when CRUD (Insert/Delete/Update) happens. You can never drag and drop them onto dbml file to create methods.
"var" will automatically recognize your returned value's type. You don't need to change that.