Click here to Skip to main content
15,886,788 members
Home / Discussions / C#
   

C#

 
GeneralRe: Error : C# foreach statement cannot operate on variable of type ? Pin
Sphinxniuie11-Aug-15 19:42
Sphinxniuie11-Aug-15 19:42 
GeneralRe: Error : C# foreach statement cannot operate on variable of type ? Pin
Wendelius11-Aug-15 20:11
mentorWendelius11-Aug-15 20:11 
GeneralRe: Error : C# foreach statement cannot operate on variable of type ? Pin
Sphinxniuie11-Aug-15 20:16
Sphinxniuie11-Aug-15 20:16 
GeneralRe: Error : C# foreach statement cannot operate on variable of type ? Pin
Sphinxniuie11-Aug-15 19:07
Sphinxniuie11-Aug-15 19:07 
Questionhow to work with WIX Pin
jamesmc153510-Aug-15 23:33
jamesmc153510-Aug-15 23:33 
AnswerRe: how to work with WIX Pin
Richard Andrew x6411-Aug-15 9:16
professionalRichard Andrew x6411-Aug-15 9:16 
GeneralRe: how to work with WIX Pin
jamesmc153511-Aug-15 20:51
jamesmc153511-Aug-15 20:51 
QuestionThreading Problem Calling DB Query Pin
Kevin Marois10-Aug-15 12:18
professionalKevin Marois10-Aug-15 12:18 
I'm posting this here because I believe this to be a threading issue, not a DB issue. FYI, I'm using SQLite with dotConnect and EF.

I'm calling a DAL function from two different places on start of my app. Basically there are two lists both being populated from a DAL call. Both places use Background workers to make the same call:
private void loadWorker_DoWork(object sender, DoWorkEventArgs e)
{
    var sensors = AppCore.AppDAL.GetSensors();
    e.Result = sensors;
}

Then in the DAL I have a call to get the sensors:
public List<SensorEntity> GetSensors()
{
    lock (lockObj)
    {
        var query = getSensorQuery();
        var results = query.OrderBy(x => x.SensorName).ToList();

<pre>
    // THIS CALLS GetSensorCategoryBELOW
    results.ForEach(x => x.Category = GetSensorCategory(x.SensorTypeID));

    return results;
}

}

private IQueryable<sensorentity> getSensorQuery()
{
var results = (from s in dataContext.Sensors
select new SensorEntity
{
ID = s.ID,
SensorTypeID = s.SensorTypeID,
SensorName = s.Name,
Description = s.Description,
Address = s.SourceAddress.Value,
LastActivityDT = s.LastUpdate
});

return results;
}



Then for each sensor I get it's Category
public SensorCategoryEntity GetSensorCategory(long ID)
{
    var query = getSensorCategoryQuery();
    var results = query.Where(x => x.ID == ID).FirstOrDefault();  //<== FAILS HERE
    return results;
}

private IQueryable<SensorCategoryEntity> getSensorCategoryQuery()
{
    var query = (from sc in dataContext.SensorTypes
                    select new SensorCategoryEntity
                    {
                        ID = sc.ID,
                        Name = sc.Name
                    });

    return query;
}

At the point indicated I get

"Object cannot be cast from DBNull to other types."

If I put in a Thread.Sleep, like below, then it works fine. if I block out the second call, it works fine.
private void loadWorker_DoWork(object sender, DoWorkEventArgs e)
{
    Thread.Sleep(500);

    var sensors = Falcon6Core.Falcon6DAL.GetSensors();
    e.Result = sensors;
}

I don't really understand what's going on here. I'm not inserting data... it's just a simple query.. Why would there be any kind of threading problem here?
If it's not broken, fix it until it is

QuestionRe: Threading Problem Calling DB Query Pin
Richard MacCutchan10-Aug-15 21:54
mveRichard MacCutchan10-Aug-15 21:54 
AnswerRe: Threading Problem Calling DB Query Pin
Kevin Marois11-Aug-15 7:54
professionalKevin Marois11-Aug-15 7:54 
AnswerRe: Threading Problem Calling DB Query Pin
Gerry Schmitz11-Aug-15 8:46
mveGerry Schmitz11-Aug-15 8:46 
AnswerRe: Threading Problem Calling DB Query Pin
Mycroft Holmes11-Aug-15 15:04
professionalMycroft Holmes11-Aug-15 15:04 
QuestionGet new index of all columns after reorder in Listview Pin
Member 1185273110-Aug-15 0:10
Member 1185273110-Aug-15 0:10 
AnswerRe: Get new index of all columns after reorder in Listview Pin
Ravi Bhavnani10-Aug-15 2:48
professionalRavi Bhavnani10-Aug-15 2:48 
QuestionMessage Closed Pin
7-Aug-15 2:14
dilipk77-Aug-15 2:14 
QuestionTarget Framework in VS Pin
Bill 10016-Aug-15 8:32
Bill 10016-Aug-15 8:32 
AnswerRe: Target Framework in VS Pin
OriginalGriff6-Aug-15 8:44
mveOriginalGriff6-Aug-15 8:44 
GeneralRe: Target Framework in VS Pin
Bill 10016-Aug-15 8:54
Bill 10016-Aug-15 8:54 
AnswerRe: Target Framework in VS Pin
Kevin Marois6-Aug-15 9:35
professionalKevin Marois6-Aug-15 9:35 
GeneralRe: Target Framework in VS Pin
Bill 100113-Aug-15 11:57
Bill 100113-Aug-15 11:57 
GeneralRe: Target Framework in VS Pin
Kevin Marois13-Aug-15 12:00
professionalKevin Marois13-Aug-15 12:00 
GeneralRe: Target Framework in VS Pin
Bill 100113-Aug-15 12:06
Bill 100113-Aug-15 12:06 
GeneralRe: Target Framework in VS Pin
Kevin Marois13-Aug-15 12:07
professionalKevin Marois13-Aug-15 12:07 
QuestionDragging A Control - Limits Pin
Kevin Marois6-Aug-15 7:24
professionalKevin Marois6-Aug-15 7:24 
AnswerRe: Dragging A Control - Limits Pin
Alan N7-Aug-15 8:07
Alan N7-Aug-15 8:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.