tags:

views:

40

answers:

1

While executing the code below I am getting HTTP 500 Internal Server Error.

public bool DeleteData(int dataId, string uploaderName)
{
    using (DataClassesDataContext db = new DataClassesDataContext())
    {
        DataInfo d = db.DataInfos.Where(c => c.DataId == dataId).Single();
        db.DataInfos.DeleteOnSubmit(d);
        db.SubmitChanges();
    }        
    return true;
}

This fetches the value in "d", but while executing db.SubmitChanges(); I see a 500 error. What can the reason be? The ID column is a primary key and also Identity.

Also I want to know how to implement "and" in LINQ, something like this:

DataInfo d = db.DataInfos.Where(c => c.DataId == DataId AND 
                                c.UploaderName==uploaderName).Single();
+2  A: 

Implementing "and" is easy - this is a C# expression, after all:

DataInfo d = db.DataInfos.Where(c => c.DataId == DataId &&
                                c.UploaderName == uploaderName).Single();

As for the 500 error, that's almost certainly due to an exception, but without the details of the exception it's hard to know what's wrong. Before you even try to fix the LINQ error, you should make sure that you log any exception which causes a request to fail. This will help you with future errors. With the logging in place, you should be able to tell us what the exception is, at which point we can help you fix it.

Jon Skeet
Thanks Jon for all your help.Actually the same code is working from another solution.
Wondering