Showing posts with label LINQ. Show all posts
Showing posts with label LINQ. Show all posts

Wednesday, July 29, 2009

LINQPad (new version) - nice tool that can help you to stady LINQ.

LINQPad is nice tool that can help you to study LINQ. I have read firs overview of this tool. Absence auto-complete grieves most people. Auto-complete is present in new version. This option requiring payment. IMHO: auto-complete is more detrimental than efficiency for studying (but very useful for work).
But I want say not about that. LINQPad is obtain other interesting feature. Author of this tool Joseph Albahari with your brother had written book "C# 3.0 in a Nutshell" and he added LINQ samples from this book to LINQPad. You can not only investigate different case moreover you can see how it look in lambda and IL code.


Investigate these samples in IL code should be very interesting ;)

Sunday, July 19, 2009

Do you know about LINQ that.. ?

Do you know about LINQ to SQL that attribute is more important than value? What is it mean? My friend have found interesting relation. He had written LINQ to SQL where he checked a column value to null but he was disappointed - it wasn't worked if it was need. He had null values in set but LINQ code didn't see they (He had written simple test code with foreach - it worked). After some investigate he has found that trouble in mapped data. Particular property was marked ColumnAttribute with set CanBeNull property false. So LINQ implicitly optimizes him code regards attribute's value (skips the check to null).
PS: It shows that we should be careful to small thing.. because small things can implicitly brings a big and strange problems.

Tuesday, May 12, 2009

Some samples of "101 LINQ Samples" aren't valid.

My previous post (101 LINQ Samples) refers to very interesting samples. But I didn't pay attention that it is announcement as "future" features. So some of these samples aren't valid (were not implemented).
I'm not one found this trouble, in this forum thread shows what we can use instead of Fold (Aggregate) and EqualAll (SequenceEqual), we should use own realization according to situations for some other operations (SelectMany, Combine).

"Everybody lies" (c) House M.D.

Thursday, May 7, 2009

101 LINQ Samples

Sometimes I work with LINQ. So I have completed a task and after some time I should try recall my knowledge of LINQ for new task. It is inconveniently as I should search some info time and again. I have found a great simple LINQ samples. It is very useful and clear for novice. So I can avoid a new recall next time :).
This document locates there - LINQ Samples.

Tuesday, March 3, 2009

OnTime desktop light client.

Download source files - here.
Download binary files - here.

My previous customer uses OnTime as bts. It is very slowly tool. I hated it! I tired to wait any respond from this app. I have created a little and more fast tool for self using. This tool ins't complete (I have stopped to work with this customer and I can't have an access to bd for continue implementation).
Next issues need a fix:
  • SQL exception isn't handled infrequent :)
  • Icons aren't useful. Useful tooltips correct this defect ;)
  • Attachment download works in some thread that GUI (It is shameful, but I haven't had time, really)
  • App works readonly.
  • Sort and Search hasn't implemented.
  • We can work with self issues only.
Advantage:
  • It is really more fast tool than official.
  • Persist state doesn't store in bd. It saves in current PC only.
Axosoft releases new version (9.0). It is more fast than previous (8.0). But it is still no enough.
If you want to implement some features or to fix bugs you need to know that for correct run sources you need to set connection string in the next files:
  1. app.config
  2. Settings.Designer.cs
  3. OTData.dbml
  4. and Settings.settings in two points.
I have changed my connect string to "your_connecting_string" for more handy replace ;).

Friday, November 21, 2008

Trips&Ticks: Do you know how you can cast Object to AnonymousType?

I experimented with LINQ in my private project and question that was showed in title took me. I had next situation:

I set list in one method:

private void SetList()
{
SomeList.ItemsSource = ( from someTable in data.SomeTable
select new
{
someTable.Id,
someTable.Name,
Priority = someTable.Priority,
} );
In other method I want retrieve Id of selected item. How can I do it? I have found interesting solution in blog of Tomas Petricek.
private Int32 GetID()
{
Object selectedItem = DefectList.SelectedItem;

if( null != selectedItem )
{
var item = Utility.Cast( selectedItem, new
{
Id = 0,
Name = String.Empty,
Priority = String.Empty,
} );

Int32 id = item.Id;
}
}
public static T Cast( object obj, T type )
{
return (T)obj;
}

PS: As for me the best way is:
  • implement class with three like property.
  • create collection with items of this class.
  • set in ItemsSource new created collection.
  • now we can easy case Object to this class.