Thursday, August 29, 2013
Monday, August 26, 2013
SSMS- get create index script from hint in execution plan
SQL Server - no created date
for indices
Thursday, August 22, 2013
How to get results in LinqPad
I had to use dump:
var pd = Products.Select(p=>p);
pd.Dump();
var pd = Products.Select(p=>p);
pd.Dump();
NuGet Package Manager - Unable to find version
Wednesday, August 21, 2013
Nuget- an error occurred
run the vs with logging to see the error
devenv.exe /log "c:\log.xml"
devenv.exe /log "c:\log.xml"
Limit profile in sql server profiler
trace file properties-> column filters->edit filters -> like etc, exclude rows etc
Thursday, August 8, 2013
Fiddler is a lifesaver with silverlight problems
The imported project "C:\Program Files\MSBuild\Microsoft\Silverlight\v5.0\Microsoft.Silverlight.CSharp.targets" was not found
download Microsoft Silverlight 5 Tools and SDK
Silverlight securityexception
for cross-domain issues add these 2 files to the root of your website
clientaccesspolicy.xml
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
<?xml version="1.0" ?>
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
crossdomain.xml
<?xml version="1.0" ?>
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
of course ,based on security change the files above
Copy with Formatting on Notepad++
Autosizing in Silverlight
use textblock not label
Wednesday, August 7, 2013
c# Action is just a delegate
for example
public static void DoIt(int a, Action<int> act)
{
Console.WriteLine("$$$$$$$$$$$$$$$$$");
act(a);
Console.WriteLine("$$$$$$$$$$$$$$$$$");
}
is equivalent to:
public delegate void action<T>(T item);
public static void DoIt2(int a, action<int> act)
{
Console.WriteLine("$$$$$$$$$$$$$$$$$");
act(a);
Console.WriteLine("$$$$$$$$$$$$$$$$$");
}
static void Main(string[]
args)
{
DoIt(56, write);
DoIt(56, writeTwice);
DoIt2(56, write);
DoIt2(56, writeTwice);
Code refactoring
- Techniques that allow for more abstraction
- Encapsulate Field – force code to access the field with getter and setter methods
- Generalize Type – create more general types to allow for more code sharing
- Replace type-checking code with State/Strategy[6]
- Replace conditional with polymorphism [7]
- Techniques for breaking code apart into more logical pieces
- Componentization breaks code down into reusable semantic units which present clear, well-defined, simple-to-use interfaces.
- Extract Class moves part of the code from an existing class into a new class.
- Extract Method, to turn part of a larger method into a new method. By breaking down code in smaller pieces, it is more easily understandable. This is also applicable to functions.
- Techniques for improving names and location of code
- Move Method or Move Field – move to a more appropriate Class or source file
- Rename Method or Rename Field – changing the name into a new one that better reveals its purpose
- Pull Up – in OOP, move to a superclass
- Push Down – in OOP, move to a subclass
from here
Extension Methods
- in order for the extension method to be visible - the method must be in a static class. If its in, lets say,the main of as console app, it will compile - you can reference it directly, but not from the instance .
- extension methods only work on instances, not static classes
Tuesday, August 6, 2013
Simple example of c# Action
public static void write(int a)
{
Console.WriteLine(a);
}
public static void
writeTwice(int a)
{
Console.WriteLine(a);
Console.WriteLine(a);
}
public static void DoIt(int a, Action<int> act)
{
Console.WriteLine("$$$$$$$$$$$$$$$$$");
act(a);
Console.WriteLine("$$$$$$$$$$$$$$$$$");
}
static void Main(string[]
args)
{
DoIt(56, write);
DoIt(56, writeTwice);
Using a for loop on a linked list
LinkedList<int> ll = new LinkedList<int>(new int[] {2, 5, 8,
2, 3, 6 });
for
(LinkedListNode<int>
node = ll.First; node != null; node =
node.Next)
{
Console.WriteLine(node.Value);
}
IEEE 754 Double Precision floating point woes
Examples of invariance in c#
class Test <T>
{
public
T y { get;
set; }
}
Test<string> r = new Test<string>();
Test<object> r2 = r;
this fails
likewise
public void consumeList(List<object> l)
{
}
consumeList(new List<object>(){"fgdg","ghffh"});
is OK while
t.consumeList(new List<string>(){"fgdg","ghffh"});
fails
Generic properties for non generic classes
are illegal
class Test
{
public
T y<T> { get;
set; }
}
instead you need the following
class Test <T>
{
public
T y { get;
set; }
}
[DataContract] = [Serializable]
[DataContract]
public class herby
{
[DataMember]
public int i {get;set;}
[DataMember]
public string s {get;set;}
}
is equivalent to
[Serializable]
public struct herby
{
public int i;
public string s;
}
Easy way to test WCF and REST services - use WebServiceHost class
static void Main(string[]
args)
{
WebServiceHost
host = new WebServiceHost(typeof(Service), new Uri("http://localhost:8000/"));
try
{
ServiceEndpoint
ep = host.AddServiceEndpoint(typeof(IService), new BasicHttpBinding(), "");
host.Open();
using
(ChannelFactory<IService>
cf = new ChannelFactory<IService>(new BasicHttpBinding(), "http://localhost:8000"))
{
//
cf.Endpoint.Behaviors.Add(new bas WebHttpBehavior());
IService
channel = cf.CreateChannel();
herby
h = channel.getHerby();
Console.WriteLine(" i:
{0}", h.i );
Console.WriteLine(" s:
{0}", h.s);
Console.WriteLine("");
Boris
b = channel.getBoris();
Console.WriteLine(" i:
{0}", h.i);
Console.WriteLine(" s: {0}",
h.s);
Console.WriteLine("");
}
Console.WriteLine("Press <ENTER> to terminate");
Console.ReadLine();
host.Close();
}
catch
(CommunicationException cex)
{
Console.WriteLine("An exception occurred: {0}",
cex.Message);
host.Abort();
}
}
empty values in WCF DataContract
could be caused by forgetting DataMember attribute
Some Basic SQL interview questions for .net developers
- what is the difference between a union and a join?
- if you have a simple table of people with amounts of money - how would you get the name of the 2nd highest owner?
- how would you get the 2nd highest amount?
- if you have a table with name company amount and you you want to have sums per company how would you filter companies with 0 and null amounts ?
- what is the difference between where and having?
- what is the difference between exists and a join?
- How would you create a database that needed to store a user name, password, and 2 phone numbers?
- What are some of the ways you can ensure unique data in a table?
- What is a CTE (common table expression) and when can it be used?
- What would be the first few things you would check to try to improve a SQL call that is taking a long time to run?
Visual Studio Reference issues
sometimes the using statement wont fail even though there is no reference
this happened to me with
using System.Runtime.Serialization;
which did not fail
this happened to me with
using System.Runtime.Serialization;
which did not fail
Friday, August 2, 2013
Thursday, August 1, 2013
HTTP Error 411. The request must be chunked or have a content length
add Content-Length: header
For System.ServiceModel.Web references
make sure the target is .net 4.0 and not client
Subscribe to:
Posts (Atom)