Click here to Skip to main content
15,907,149 members
Home / Discussions / C#
   

C#

 
GeneralRe: comparing volatile integer Pin
manustone23-Nov-09 23:44
manustone23-Nov-09 23:44 
GeneralRe: comparing volatile integer Pin
Luc Pattyn23-Nov-09 23:55
sitebuilderLuc Pattyn23-Nov-09 23:55 
AnswerSurprise! Pin
harold aptroot24-Nov-09 2:19
harold aptroot24-Nov-09 2:19 
GeneralRe: Surprise! Pin
manustone24-Nov-09 2:47
manustone24-Nov-09 2:47 
GeneralRe: Surprise! Pin
harold aptroot24-Nov-09 3:19
harold aptroot24-Nov-09 3:19 
Questioni have problem axShockwaveFlash1_OnProgress [modified] Pin
bekzod00923-Nov-09 19:14
bekzod00923-Nov-09 19:14 
AnswerRe: i have problem axShockwaveFlash1_OnProgress Pin
Richard MacCutchan23-Nov-09 21:52
mveRichard MacCutchan23-Nov-09 21:52 
QuestionLinq question, error I do not understand Pin
Calvin Bell23-Nov-09 12:49
Calvin Bell23-Nov-09 12:49 
I inherited a project at my job, and there is a line of code that is giving me an error. I am having trouble figuring it out.

In the method below, data is being pulled from a table, and put into a CustomerData object. The "Expiration" line, which is a DateTime, is the one that is erroring. If I take out this part: "() =&gt; new License()" in the .FirstOrDefault method, it compiles, but when I click on the part that populates the grid I get "Object reference not set to an instance of an object.". If I try to compile with this part: "() =&amp;gt; new License()" it gives me this error: "The type arguments for method 'System.Linq.Enumerable.FirstOrDefault<TSource>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,bool>)' cannot be inferred from the usage. Try specifying the type arguments explicitly."
If I assign "Expiration" to a static DateTime, then it works fine and populates the return with all the same date/time.

So, I think the linq part of the statement is wrong and I am getting null back (when the field is not nullable), or I need to specify the type somewhere in there.

Any help would be appreciated!

internal static IEnumerable<CustomerData> GetCustomers(this HttpRequest request)
{
var dc = new RootDataContext();

return dc.Customers.ToList().Select(c => new CustomerData()
{
CustomerId = c.CustomerID,
StoreNumber = c.StoreNumber,
StoreName = c.StoreName,
OwnerName = c.OwnerName,
City = c.City,
State = c.State,
TimeZone = c.TimeZone,
//Compile time error, "specify type"
//Expiration = c.Licenses.Where(l => l.ProductID > 1002).OrderBy(l => l.Expiration).FirstOrDefault(() => new License()).Expiration,
//Compiles, errors "null reference"
//Expiration = c.Licenses.Where(l => l.ProductID > 1002).OrderBy(l => l.Expiration).FirstOrDefault().Expiration,
//works, all the same datetime
//Expiration = new DateTime(2010, 12, 10),
Trial = c.Licenses.Where(l => l.ProductID > 1002).Any(l => l.Trial),
InventoryDate = c.Products_Database_Eagle != null ? c.Products_Database_Eagle.InventoryDate : default(DateTime),
Upload = c.Products_Database_Eagle != null ? c.Products_Database_Eagle.Upload : false,
Finalize = c.Products_Database_Eagle != null ? c.Products_Database_Eagle.Finalize : false,
Registration = c.RegistrationKey,
});
}
AnswerRe: Linq question, error I do not understand Pin
Ravi Bhavnani23-Nov-09 13:49
professionalRavi Bhavnani23-Nov-09 13:49 
GeneralRe: Linq question, error I do not understand Pin
Calvin Bell24-Nov-09 2:49
Calvin Bell24-Nov-09 2:49 
GeneralRe: Linq question, error I do not understand Pin
Ravi Bhavnani24-Nov-09 3:52
professionalRavi Bhavnani24-Nov-09 3:52 
Questioncan TcpClient :: GetStream() be used in separate threads for the same TcpClient ? Pin
abiemann23-Nov-09 12:44
abiemann23-Nov-09 12:44 
AnswerRe: can TcpClient :: GetStream() be used in separate threads for the same TcpClient ? Pin
April Fans24-Nov-09 0:32
April Fans24-Nov-09 0:32 
AnswerRe: can TcpClient :: GetStream() be used in separate threads for the same TcpClient ? Pin
Paulo Zemek24-Nov-09 1:15
Paulo Zemek24-Nov-09 1:15 
GeneralRe: can TcpClient :: GetStream() be used in separate threads for the same TcpClient ? Pin
abiemann30-Nov-09 6:41
abiemann30-Nov-09 6:41 
QuestionWebbrowser control print preview not working for background color Pin
Shukra23-Nov-09 12:04
Shukra23-Nov-09 12:04 
AnswerRe: Webbrowser control print preview not working for background color Pin
Dave Kreskowiak23-Nov-09 12:52
mveDave Kreskowiak23-Nov-09 12:52 
AnswerRe: Webbrowser control print preview not working for background color Pin
Ravi Bhavnani23-Nov-09 13:55
professionalRavi Bhavnani23-Nov-09 13:55 
GeneralRe: Webbrowser control print preview not working for background color Pin
Shukra23-Nov-09 17:23
Shukra23-Nov-09 17:23 
AnswerRe: Webbrowser control print preview not working for background color Pin
Ravi Bhavnani23-Nov-09 17:47
professionalRavi Bhavnani23-Nov-09 17:47 
QuestionEmgu CV Vs AForge.NET Vs OpenCVDotNet Pin
Lynndah21223-Nov-09 8:55
Lynndah21223-Nov-09 8:55 
AnswerRe: Emgu CV Vs AForge.NET Vs OpenCVDotNet Pin
Dave Kreskowiak23-Nov-09 10:18
mveDave Kreskowiak23-Nov-09 10:18 
GeneralRe: Emgu CV Vs AForge.NET Vs OpenCVDotNet Pin
Lynndah21223-Nov-09 11:14
Lynndah21223-Nov-09 11:14 
GeneralRe: Emgu CV Vs AForge.NET Vs OpenCVDotNet Pin
Dave Kreskowiak23-Nov-09 12:51
mveDave Kreskowiak23-Nov-09 12:51 
QuestionRead and Write a file at the same time? Pin
Tony496623-Nov-09 4:41
Tony496623-Nov-09 4:41 

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.