473,387 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Easy way* to cast an object in a LINQ query? Methinks not*

Inspired by Chapter 8 of Albahari's excellent C#3.0 in a Nutshell
(this book is amazing, you must get it if you have to buy but one C#
book) as well as Appendix A of Jon Skeet's book, I am going through
some LINQ queries. But how to cast? (

See the below, modified from somebody else's code.

The problem is the query 'stops' (throws a cast exception) at "3", and
never gets to "violet".

How to prevent this?

Pseudocode OK, just a hint is all I need, but more of course is
better.

RL

*PS--by "easy way to cast" I mean something very short, that can work
at runtime, not something like a CASE/SWITCH statement that lists all
possibilities ahead of time, but, I'll take all answers.

//
List<objectwords = new List<object{ "green", "blue", 3, "violet",
5 };

// Cast the objects in the list to type 'string'
// and project the first two letters of each string.

try
{
IEnumerable<stringquery =
words.AsQueryable().Cast<string>().Select(str =str.Substring(0, 2));

foreach (string s in query)
Console.WriteLine(s);
}

catch (ArgumentException ex)
{
Console.WriteLine(ex);
}
catch (InvalidCastException ex2)
{
Console.WriteLine("invalid cast!" + ex2);
}

/* This code *should* produce the following output, but
it breaks out of the query when it gets to '3' above and throws an
InvalidCastException--how to get it to complete the query until the
end?

gr
bl
vi
*/

RL
Sep 22 '08 #1
20 2854
I suggest a change your critical line to:

IEnumerable<stringquery =
words.AsQueryable().Cast<string>().Select(str =str.Substring(0,
Math.Min(str.Length, 2)));

"raylopez99" <ra********@yahoo.comwrote in message
news:c6**********************************@e39g2000 hsf.googlegroups.com...
Inspired by Chapter 8 of Albahari's excellent C#3.0 in a Nutshell
(this book is amazing, you must get it if you have to buy but one C#
book) as well as Appendix A of Jon Skeet's book, I am going through
some LINQ queries. But how to cast? (

See the below, modified from somebody else's code.

The problem is the query 'stops' (throws a cast exception) at "3", and
never gets to "violet".

How to prevent this?

Pseudocode OK, just a hint is all I need, but more of course is
better.

RL

*PS--by "easy way to cast" I mean something very short, that can work
at runtime, not something like a CASE/SWITCH statement that lists all
possibilities ahead of time, but, I'll take all answers.

//
List<objectwords = new List<object{ "green", "blue", 3, "violet",
5 };

// Cast the objects in the list to type 'string'
// and project the first two letters of each string.

try
{
IEnumerable<stringquery =
words.AsQueryable().Cast<string>().Select(str =str.Substring(0, 2));

foreach (string s in query)
Console.WriteLine(s);
}

catch (ArgumentException ex)
{
Console.WriteLine(ex);
}
catch (InvalidCastException ex2)
{
Console.WriteLine("invalid cast!" + ex2);
}

/* This code *should* produce the following output, but
it breaks out of the query when it gets to '3' above and throws an
InvalidCastException--how to get it to complete the query until the
end?

gr
bl
vi
*/

RL
Sep 22 '08 #2
raylopez99 <ra********@yahoo.comwrote:
Inspired by Chapter 8 of Albahari's excellent C#3.0 in a Nutshell
(this book is amazing, you must get it if you have to buy but one C#
book) as well as Appendix A of Jon Skeet's book, I am going through
some LINQ queries. But how to cast? (

See the below, modified from somebody else's code.

The problem is the query 'stops' (throws a cast exception) at "3", and
never gets to "violet".

How to prevent this?
See the "OfType" method.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Sep 22 '08 #3
By the way, the reason I said this is that I don't get an invalid cast, but
rather
an index out of range error...
"Family Tree Mike" <Fa************@ThisOldHouse.comwrote in message
news:uO**************@TK2MSFTNGP04.phx.gbl...
>I suggest a change your critical line to:

IEnumerable<stringquery =
words.AsQueryable().Cast<string>().Select(str =str.Substring(0,
Math.Min(str.Length, 2)));

"raylopez99" <ra********@yahoo.comwrote in message
Sep 22 '08 #4


Family Tree Mike wrote:
I suggest a change your critical line to:

IEnumerable<stringquery =
words.AsQueryable().Cast<string>().Select(str =str.Substring(0,
Math.Min(str.Length, 2)));
FTM--that didn't do anything important (or so it seems, but I left it
in anyway, figuring you must be guarding against something), i.e., you
still got the exception thrown. What was it supposed to guard
against?

Anyway, I took Jon Skeet's idea to mind, and here is what worked. I
have a feeling the extra ".Cast<>" below is redundant...but don't see
a problem leaving it in.

RL

//this worked...add-- OfType<string>(). in the middle as shown

IEnumerable<stringquery =
words.AsQueryable().OfType<string>().Cast<string>( ).Select(str =>
str.Substring(0,Math.Min(str.Length, 2)));
Sep 22 '08 #5
I see...index out of range would be if you did not put an index that's
within the string length...makes sense... so ignore my question to you
in the prior post.

Thank you.

Family Tree Mike wrote:
By the way, the reason I said this is that I don't get an invalid cast, but
rather
an index out of range error...
Sep 22 '08 #6
Just so we are clear, now I get no exceptions within this code, and the
output is:

gr
bl
3
vi
5

"raylopez99" <ra********@yahoo.comwrote in message
news:24**********************************@73g2000h sx.googlegroups.com...
>I see...index out of range would be if you did not put an index that's
within the string length...makes sense... so ignore my question to you
in the prior post.

Thank you.

Family Tree Mike wrote:
>By the way, the reason I said this is that I don't get an invalid cast,
but
rather
an index out of range error...
Sep 22 '08 #7
Yes, thanks, that worked "OfType".

I'm getting the hang of this Linq. Con permission, I would like to
upload your Appendix A and also Albahari's Linq examples from Chapter
8 of his excellent book "C#3.0 in a Nutshell". A little cheat sheet
of Linq, since otherwise you have to buy a huge 1000 page tome (which
I've ordered as well).

If you're worried about copyright infringement I can work the examples
some to make them 'unique', per our conversation about artistic
license. Besides it's well known that supplying examples on the web
will increase print sales...

I like your book--so far up to p. 62 "Part 2".

The best part so far IMO:

- Listing 2.1 Using Delegates in a variety of simple ways. The best
explanation of delegates I've seen so far, but, I will say by now I am
pretty familiar with delegates / events so maybe that's why (with
hindsight it seems so easy). But I'd never seen .Invoke in delegate
before your book (normally it's not mentioned, since implicit).

- p. 54 "Summary of Value types and Reference types" - this was good,
but this *key* sentence should be amplified IMO "When a reference type
is used as a method parameter, by default the parameter is passed _by
value_--but the value itself is a reference". You should highlight
and expound on "but the value itself is a reference" IMO because this
is where newbies like me get confused. You should add--"..and in C#,
you can change a reference type variable calling a method through a
reference passed by value to a method, in exactly the same way as
through a reference type passed by reference to the method, so long as
'new' is not used in the method". Well, that's the idea, perhaps you
can break up this compound sentence. What threw me (from a C++
background) is the fact that they use copy constructors and const in C+
+ and I thought that 'pass by value' (for a reference type variable)
meant a 'copy' that doesn't change the original--I'm sure other
newbies have made this mistaken assumption too.

Other stuff I like but I'll get to it later maybe.

And Func (p.56) too I now like--now I get it--Albahari on p. 119 also
discusses this useful syntax.

Jon Skeet [ C# MVP ] wrote:
See the "OfType" method.

Sep 23 '08 #8
On Sep 23, 12:56*am, raylopez99 <raylope...@yahoo.comwrote:
Yes, thanks, that worked "OfType".
Why are you calling AsQueryable() by the way?
I'm getting the hang of this Linq. *Con permission, I would like to
upload your Appendix A and also Albahari's Linq examples from Chapter
8 of his excellent book "C#3.0 in a Nutshell". *A little cheat sheet
of Linq, since otherwise you have to buy a huge 1000 page tome (which
I've ordered as well).
No, I'd rather you didn't do that. You'd have to ask Joe/Ben about C#
in a Nutshell, although it's worth checking whether the examples are
already available in downloadable source code.
If you're worried about copyright infringement I can work the examples
some to make them 'unique', per our conversation about artistic
license. *Besides it's well known that supplying examples on the web
will increase print sales...
That's a matter for myself and Manning to work out, however. Yes, I
like appendix A as well and think it's useful - but I would rather you
didn't take it upon yourself to publish it. If Manning and I choose to
make that available for free (there are already a couple of chapters
downloadable for free) then that's our decision to take. I will
mention it to the publisher though.

In terms of cheat sheets, you might want to look at http://refcardz.dzone.com
I like your book--so far up to p. 62 "Part 2".

The best part so far IMO:

- Listing 2.1 Using Delegates in a variety of simple ways. *The best
explanation of delegates I've seen so far, but, I will say by now I am
pretty familiar with delegates / events so maybe that's why (with
hindsight it seems so easy). *But I'd never seen .Invoke in delegate
before your book (normally it's not mentioned, since implicit).
I'm glad you're getting more comfortable with them - although I wish
you'd step away from the idea that they're like GOTO statements
(they're really not).
- p. 54 "Summary of Value types and Reference types" - this was good,
but this *key* sentence should be amplified IMO "When a reference type
is used as a method parameter, by default the parameter is passed _by
value_--but the value itself is a reference". *You should highlight
and expound on "but the value itself is a reference" IMO because this
is where newbies like me get confused. *You should add--"..and in C#,
you can change a reference type variable calling a method through a
reference passed by value to a method, in exactly the same way as
through a reference type passed by reference to the method, so long as
'new' is not used in the method". *Well, that's the idea, perhaps you
can break up this compound sentence. *What threw me (from a C++
background) is the fact that they use copy constructors and const in C+
+ and I thought that 'pass by value' (for a reference type variable)
meant a 'copy' that doesn't change the original--I'm sure other
newbies have made this mistaken assumption too.
I originally had quite a long example with a blow-by-blow explanation
- I can't remember how much of it is still there. However, it's very
difficult to make this topic clear - I found your explanation above
very confusing (particularly uses of the word "through"). I have yet
to discover the "perfect" way of explaining the whole business (which
goes much deeper than just method parameters - it's fundamental to how
you understand variables, garbage collection, assignment, etc). I
haven't seen anyone else do a stellar job of explaining it either,
otherwise I'd defer to them. It's one of those things that just takes
a while before the lightbulb comes on.
Other stuff I like but I'll get to it later maybe.

And Func (p.56) too I now like--now I get it--Albahari on p. 119 also
discusses this useful syntax.
Not sure exactly what you're referring too - Func is a delegate type,
not a piece of syntax. I guess you mean either lambda expressions or
anonymous methods, but I don't have the book with me right now, so I
can't really tell.

Jon
Sep 23 '08 #9
raylopez99 wrote:
I am going through some LINQ queries.
No, you are not. You are using extension methods and lambda expressions,
but no LINQ.

--
Göran Andersson
_____
http://www.guffa.com
Sep 23 '08 #10
On Sep 22, 11:05*pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Sep 23, 12:56*am, raylopez99 <raylope...@yahoo.comwrote:
Yes, thanks, that worked "OfType".

Why are you calling AsQueryable() by the way?
I don't know--it was in the code I copied. I took it out and the
query works fine. Also I took out the cast and it works fine, but
raises a question**.

Here is the reduced query that works:

IEnumerable<stringquery = words.OfType<string>().Select(str =>
str.Substring(0, Math.Min(str.Length, 2)));

**BTW, I found something of interest today. You can break a query
into two (see *below for an example), but, a question is raised:

if you have two queries separate, then the first one can trigger an
exception before the second one can override. What I mean is this:

it seems that in this query:
IEnumerable<stringquery =
words.OfType<string>().Cast<string>().Select(str =str.Substring(0,
2));

That the OfType<string>() 'overrides' the Cast<(because it seems
that with this functional type expression the final expression is not
evaluated until everything on the RHS is run). Thus you never get the
Exception thrown by .Cast<>, because .OfType<overrides it.

But, if you were to break up this into two queries, what would
happen? Time to find out...wait...

OK, just as I thought: the exception is thrown! The *disadvantage*
of using multiple queries rather than all in one line.

Here it is:

// List<objectwords = new List<object{ "green",
"blue", 3, "violet", 5 };

IEnumerable<stringquery1 =
words.Cast<string>().Select(str =str.Substring(0,
Math.Min(str.Length, 2))); //breaking up original query into 'query1'
and 'query2'

IEnumerable<stringquery2 =
query1.OfType<string>(); // this is legal

foreach (string s in query2) //runtime error! since
query1 fails (throws an exception at element '3')

//ironically, breaking up the original query into two queries results
in a runtime error; had we left the original query alone we'd be
fine.
Another valuable contribution to theory.

No, I'd rather you didn't do that. You'd have to ask Joe/Ben about C#
in a Nutshell, although it's worth checking whether the examples are
already available in downloadable source code.

OK, no worries. Don't bother yourself asking, I just thought it would
be useful. You realize your publisher is like a wedding photographer
with your wedding pictures...if they're nice, it's not a problem, but
if they become hostile...
>
In terms of cheat sheets, you might want to look athttp://refcardz.dzone.com
Excellent. Thanks I signed up and downloaded them, very nice.
>
I like your book--so far up to p. 62 "Part 2".
The best part so far IMO:
- Listing 2.1 Using Delegates in a variety of simple ways. *The best
explanation of delegates I've seen so far, but, I will say by now I am
pretty familiar with delegates / events so maybe that's why (with
hindsight it seems so easy). *But I'd never seen .Invoke in delegate
before your book (normally it's not mentioned, since implicit).

I'm glad you're getting more comfortable with them - although I wish
you'd step away from the idea that they're like GOTO statements
(they're really not).
OK but they are "in my mind's eye".
- p. 54 "Summary of Value types and Reference types" - this was good,
but this *key* sentence should be amplified IMO "When a reference type
is used as a method parameter, by default the parameter is passed _by
value_--but the value itself is a reference". *You should highlight
and expound on "but the value itself is a reference" IMO because this
is where newbies like me get confused. *You should add--"..and in C#,
you can change a reference type variable calling a method through a
reference passed by value to a method, in exactly the same way as
through a reference type passed by reference to the method, so long as
'new' is not used in the method". *Well, that's the idea, perhaps you
can break up this compound sentence. *What threw me (from a C++
background) is the fact that they use copy constructors and const in C+
+ and I thought that 'pass by value' (for a reference type variable)
meant a 'copy' that doesn't change the original--I'm sure other
newbies have made this mistaken assumption too.

I originally had quite a long example with a blow-by-blow explanation
- I can't remember how much of it is still there. However, it's very
difficult to make this topic clear - I found your explanation above
very confusing (particularly uses of the word "through"). I have yet
to discover the "perfect" way of explaining the whole business (which
goes much deeper than just method parameters - it's fundamental to how
you understand variables, garbage collection, assignment, etc). I
haven't seen anyone else do a stellar job of explaining it either,
otherwise I'd defer to them. It's one of those things that just takes
a while before the lightbulb comes on.
OK, that's interesting. I use the word "through" loosely, since I
never have figured out the convention in "calling method" or "called
method" or whatever. One code calls the other, I think the method,
like a procedure/sub procedure. Anyway, that's how I call it (mind's
eye).
>
Other stuff I like but I'll get to it later maybe.
And Func (p.56) too I now like--now I get it--Albahari on p. 119 also
discusses this useful syntax.

Not sure exactly what you're referring too - Func is a delegate type,
not a piece of syntax. I guess you mean either lambda expressions or
anonymous methods, but I don't have the book with me right now, so I
can't really tell.
Thanks. Also your book reviews are helpful. I think Albahari et al.
C# Nutshell reference book is the best C# book ever. Packed w/
information. Also useful is the C# Recipe book by O'Reilly.
Goodbye,

RL

** // example showing a query broken up into two queries
for readability

string[] names = { "Tom", "Dick", "harry" };
IEnumerable<stringfilteredNames1 =
System.Linq.Enumerable.Where(names, n =n.Length >= 4);

foreach (string n in filteredNames1)
Console.Write(n + "|"); //Dick|Harry|

IEnumerable<stringfilteredNames2 =
System.Linq.Enumerable.Where(filteredNames1, n =n.Length <= 4);
Console.WriteLine("\n");
foreach (string n in filteredNames2)
Console.WriteLine(n + "|"); //Dick
Sep 23 '08 #11
On Sep 23, 6:54*am, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
Haven't looked at the C# Recipe book. Lots more books to review... (I
don't think anyone can really say what "the best C# book ever" is
until they've read *all* of them, by the way.)
If you have the MSDN site link that loads when you load the Help in VS
(the front page) pls let me know--once your review was listed there.
For some reason I lost it and now I can't find it despite Google.

RL
Sep 23 '08 #12
On Sep 23, 4:09*pm, raylopez99 <raylope...@yahoo.comwrote:

<snip>
*IEnumerable<stringquery2 = OfType<string>().query;

This will not compile. *ANy other ideas?
Why would you expect that to compile? "query" isn't a member of
IEnumerable<Twhich is returned by OfType<stringand you need
something to call OfType<stringon in the first place.

I suggest you take a step back and try to understand extension methods
better so you can really pick apart what's going on in a LINQ query.
Experimenting by randomly reordering bits of code is going to be a
very time-consuming way of gaining any sort of understanding.

Jon

Sep 23 '08 #13
On Sep 23, 4:10*pm, raylopez99 <raylope...@yahoo.comwrote:
Haven't looked at the C# Recipe book. Lots more books to review... (I
don't think anyone can really say what "the best C# book ever" is
until they've read *all* of them, by the way.)

If you have the MSDN site link that loads when you load the Help in VS
(the front page) pls let me know--once your review was listed there.
For some reason I lost it and now I can't find it despite Google.
All my book reviews appear on my blog:
http://msmvps.com/jon.skeet

Some of them will appear on the VS C# channel, but not all - and I
won't always be able to predict which.

Jon
Sep 23 '08 #14
>>
Pro LINQ: Language Integrated Query in C# 2008 (Windows.Net)
(Paperback) - 600 pages (rounds to 1000).
<<

hehe, if you round in ten thousands it rounds to zero. Why didn't you say
"That book with no pages" :-)

>>
"Thanks" for your "help". I didn't mean to attack you personally.
Yes I did.
<<

I haven't bothered to read this thread at all, I just happened to spot this
comment. Jon's a knowledgable and very helpful guy, why you would want to
attack him I don't know. If you're nice to people in here you'll get a lot
more help and learn a lot more. Or you can insult people and eventually
start to get ignored. For example, I stopped work for a few minutes to
think up the free/foreach example, write it, test it, just to make sure I
could paste code that you could execute. I wouldn't do that for someone
without manners.
Regards

Pete

Sep 23 '08 #15
raylopez99 <ra********@yahoo.comwrote:

<snip>

As I've said before, I won't offer any help while you're being rude. If
you're still interested in the topic, put a bit of effort (five minutes
ought to do it) and try again - then post a *civil* message if you have
any more problems.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Sep 24 '08 #16
OK "sorry" for not being (in your mind's eye) "civil". My apologies.

Now, yes, I found a solution. Here it is:

List<objectwords = new List<object{ "green", "blue", 3, "violet",
5 };

IEnumerable<stringquery = words.OfType<string>().Select(str =>
str.Substring(0, Math.Min(str.Length, 2)));
IEnumerable<stringquery2 = query.Cast<string>();
//works because cast follows OfType (always safer since Cast throws
exception while OfType does not)

You simply have to remember that OfType should preceed Cast and not
follow it, because OfType does not throw an exception, while Cast
does.

I even just noticed that in your Appendix A of your book you mention
this (Table A.3).

But a larger question is this--given a try/catch block, how can you
catch an exception that's of type InvalidCastException, and then
continue in the 'try' block after the exception is thrown? Pseudocode
or even just a short answer in words is OK, just a hint is all I'm
seeking.

"Thanks", "in advance".

RL

Sep 24 '08 #17
On Sep 24, 10:00*am, raylopez99 <raylope...@yahoo.comwrote:
OK "sorry" for not being (in your mind's eye) "civil". *My apologies.
Thank you. And clearly not just in my mind's eye, either - see the
response from Peter Morris.
Now, yes, I found a solution. *Here it is:

List<objectwords = new List<object{ "green", "blue", 3, "violet",
5 };

IEnumerable<stringquery = words.OfType<string>().Select(str =>
str.Substring(0, Math.Min(str.Length, 2)));
IEnumerable<stringquery2 = query.Cast<string>();
*//works because cast follows OfType (always safer since Cast throws
exception while OfType does not)

You simply have to remember that OfType should preceed Cast and not
follow it, because OfType does not throw an exception, while Cast
does.
You should also remember that using Cast after OfType is basically
pointless (assuming you're supplying the same type argument in both
places). You're saying, "Give me all the strings from the sequence"
and then "make sure everything is a string". What benefit do you
believe the call to Cast is providing?
I even just noticed that in your Appendix A of your book you mention
this (Table A.3).

But a larger question is this--given a try/catch block, how can you
catch an exception that's of type InvalidCastException, and then
continue in the 'try' block after the exception is thrown? *Pseudocode
or even just a short answer in words is OK, just a hint is all I'm
seeking.
You'd have to use a loop - and because the exception happens in the
implicit call to MoveNext() supplied by foreach, you'd pretty much
have to write the iteration by hand. However, that would only work if
the iterator then moved on beyond the "broken" element. I don't know
offhand whether it does. Continuing to use an iterator after it's
thrown an exception strikes me as a very bad idea.

Jon
Sep 24 '08 #18
However, that would only work if
the iterator then moved on beyond the "broken" element. I don't know
offhand whether it does.
For an iterator block, it won't. The generated code sets the state to
EOF at the start of every MoveNext(), and only puts it back to
something meaningful if the block completes - saves on a try/catch I
guess.

So it certainly isn't a safe approach, even if it happens to work for
some rare systems.

Marc
Sep 24 '08 #19
OK, thanks Marc and Jon. I will make note of this in my notes.

RL

Marc Gravell wrote:
However, that would only work if
the iterator then moved on beyond the "broken" element. I don't know
offhand whether it does.

For an iterator block, it won't. The generated code sets the state to
EOF at the start of every MoveNext(), and only puts it back to
something meaningful if the block completes - saves on a try/catch I
guess.

So it certainly isn't a safe approach, even if it happens to work for
some rare systems.

Marc
Sep 24 '08 #20

On Wed, 24 Sep 2008 02:00:50 -0700 (PDT), raylopez99
<ra********@yahoo.comwrote:
>
But a larger question is this--given a try/catch block, how can you
catch an exception that's of type InvalidCastException, and then
continue in the 'try' block after the exception is thrown? Pseudocode
or even just a short answer in words is OK, just a hint is all I'm
seeking.
The simple answer is to re-organize the code so that the desired point
of continuation follows the catch block. The complex answer questions
the overall design that requires the initial question being asked.

regards
A.G.
Sep 24 '08 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: ssg31415926 | last post by:
I need to cast a string into an object and vice versa. At the moment, I'm using code like this: int numOfObjects = Values.Length; object objects = new object; for(int i = 0; i < numOfObjects;...
0
by: Marshal | last post by:
I've just had a chance to review LINQ, DLinq, and XLinq, (which I only heard about last week after the PDC). The various LINQs actually seem to live up to expectations - Using query semantics to...
4
by: BeSharp | last post by:
I recently stumbled across a pretty interesting LINQ to SQL question and wonder, whether anybody might have an answer. (I'm doing quite some increasing LINQ evangelism down here in Germany.). ...
1
by: Matt Sollars | last post by:
Hi! Does anyone know how to reference the object created via an object initializer when setting a child property? It's hard to write into a sentence. Suppose the following summary class for a...
5
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
After having played around with LINQ and reading the literature on it I have not been successful in getting this to work so I am looking for some guidance: I want to find a hunk in a collection...
2
by: Neil Chambers | last post by:
All, I have a class describing various actions to take against a LINQ to SQL datasource. What are the pros/cons of instantiating the LINQ object either in the root of the class (for lack of a...
9
by: Cirene | last post by:
I'm about to begin a brand new, big, ASP.NET project (using 3.5 .net fw), VS 2008. I'm using MySQL as the backend (customer request.) I have absolutely no experience with LINQ and/or the Entity...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
2
by: jelle79 | last post by:
Hi all, I'm storing all kind of data stored in objects. Now I want to query my data-source. And I thought LINQ is the right thing for it. Data is stored like: store.Database Queries like...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.