Tuesday, August 6, 2013

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