Friday, March 2, 2012

The purpose of N in sql server

is to denote that the literal is unicode
some stored procedures only take nvarchar so then the N would be necessary
Here and here

Issue with sql server agent

I've had many issues in the past with permissions to start -



being fixed thus:
http://blog.sqlauthority.com/2011/03/29/sql-server-fix-error-the-request-failed-or-the-service-did-not-respond-in-timely-fashion-consult-the-event-log-or-other-applicable-error-logs-for-details/

this time I just had to restart from services

Lambda Expressions

Does C# absolutely need Lambda's? I dont think so , but it sure helps with LINQ
this is more C# like
PropertyInfo[] p = t.GetProperties();
            IEnumerable<string> names = p.Where(nms => nms.Name.StartsWith("S")).Select(nms => nms.Name);   
than: 
var names = from nms in p
            where nms.Name.StartsWith("S")             
            select nms.Name;

Anonymous Delegates

I thought a good place for Anonymous Delegates would be in dynamically created menu items that all do the same thing. This is also a good place for lambda expressions.


an interesting point


lets say I am adding a click event handler to a menu item
this is legal

ti2.Click +=  delegate { this.textBox1.Text = nav.Value; };
even though there are no arguments

this is not:
ti2.Click += () => { this.textBox1.Text = nav.Value; };

you need the input parameters

ti2.Click +=  (o,a  )=>{ this.textBox1.Text = nav.Value; };

Thursday, March 1, 2012

projection in LINQ

if you are not projecting the selected object into a new object then you don't need select
consider:

this.listBox1.Items.Clear();
            Type t = this.GetType();
            PropertyInfo[] p = t.GetProperties();
            IEnumerable<PropertyInfo> names = p.Where(cust => cust.Name.StartsWith("S"));
            foreach (PropertyInfo s in names)
            {
                this.listBox1.Items.Add(s.Name);
                       }

here we are returning a property info object and there we need not the select

but here:

this.listBox1.Items.Clear();
            Type t = this.GetType();
            PropertyInfo[] p = t.GetProperties();
            IEnumerable<string> names = p.Where(cust => cust.Name.StartsWith("S")).Select(cust => cust.Name);    //from nms in p select nms.Name;
            foreach (string s in names)
            {
                this.listBox1.Items.Add(s);
            }
we need the select because we are changing the projected type

var in c#

why does c# have a var keyword ?
if you answer because of linq- that would be partly correct
consider:
Type t = this.GetType();
PropertyInfo[] p = t.GetProperties();
var names = from nms in p select nms.Name;

in this case the var is not necessary

the following could be written


We need var in a case where we are using implicitly typed local variables:

this.listBox1.Items.Clear();
            Type t = this.GetType();
            PropertyInfo[] p = t.GetProperties();
            var names = from nms in p select new {Name = nms.Name,Typ =nms.PropertyType};
            foreach (var s in names)
            {
                this.listBox1.Items.Add(s.Name +" "+ s.Typ.ToString());  
            }



IEnumerable<string> names = from nms in p select nms.Name;

The difference between a Join and a Union

a wit once said the difference is that a union is additive while a join is multiplative

this is just part of the story, of course

a union joins like data while a join joins disparate data