SQL Server Performance Debugging Tips

February 27, 2016

ing Indexes current database by Index Advantage

Source: SQL Server Performance Debugging Tips

Understanding Polymorphism in OOP Languages: Abstract Classes vs. Interfaces

February 27, 2016

Found an awesome post in LinkedIn blog. It has been explained very well on this regard. Can’t control sharing to the followers:🙂

Here you go…..and hope you would love reading!

https://www.linkedin.com/pulse/understanding-polymorphism-oop-languages-abstract-classes-jason-roell

Courtesy to : Jason Roell

 

C# 7 feature request #1… extension attributes

January 13, 2015

Jon Skeet's coding blog

Last week I learned that using static is going to be the syntax for importing static members (including extension methods) in C# 6. That fulfils a feature request I made in September 2005 (my fourth ever blog post, as it happens). With a feature request turnaround of 10 years, I figure I should get put everything I could ever want out there now… (Just kidding really – more seriously, I’m really pleased to see this change in C# 6, relative to both C# 5 and the earlier designs of C# 6.)

Last week at CodeMash, Dustin Campbell demonstrated one Roslyn DiagnosticAnalyzer for ArgumentNullException and friends, and I demonstrated one I’d written for the JetBrains InvokerParameterName attribute. (Dustin’s isn’t available online yet; I’ll edit this post when it is.) The two diagnostics check largely the same thing: some parameters are “special” in that the argument for them should be…

View original post 399 more words

Classroom phrases

January 11, 2015

How to Praise Your Students – Nice list of 100!

Zeboniso's Weblog

Ибораҳои синфї

Зебониссо Муродова
Муаллимаи забони англиси
Мактаби тахсилоти миёнаи умуми №1 шахри Сарбанд

Хеле хуб мешуд,ки сўҳбатҳои аввал (ибораҳои синфї) дар дарсҳо бо забони англисї мешуд, то ин,ки хонандагон бо ибораҳои англисї одат кунанд. Масалан, агар шумо ибораи let’s begin-ро истифода баред шарт нест,ки ин ибораро аз ёд кунад.Агар шумо ин ибораро дар аввали ҳар дарс истифода баред, он гоҳ хонадагон мазмуни онро мефаҳманд ва аз худ мекунанд. Баъдтар агар шумо калимаи begin-ро шинос кунед хонадагон аллакай медонанд, кай дар куљо ин калимаро истифода бурдан даркор.
Ба хонадагон ибораҳои синфиро мувофиқи қобилияти синну сол омўзонидан даркор.Мо метавонем дар рўзномаи деворї ибораҳои синфиро (Classroom expression) яъне ( Hello, Good morning, How are you May I come in? May I read? May I come to the blackboard? I am ready for the lesson. ) бо забони англисї нависем ва ба девор овезонем, то ин ки ҳамаи хонадагон бо он шинос шаванд…

View original post 1,504 more words

NHibernate 3.0+ rounding a decimal data to 5 decimal places

March 14, 2014

Note: Precision is the number of digits in a number. Scale is the number of digits to the right of the decimal point in a number. For example, the number 123.45 has a precision of 5 and a scale of 2.

Problem: One of our team member was trying to to insert data into a SQL Server database from an application that is using NHibernate ver. 3.1. The format for a decimal datatype value is being forced to decimal(16,5) always, regardless of the SCALE defined for the column (ex: DECIMAL_VALUE1 decimal(16,6) in the SQL Server table. This results in decmial values being truncated before being written to the SQL Server database.

Here is the sample sql profiler trace:

exec sp_executesql N’INSERT INTO TEST_TABLE( DECIMAL_VALUE1, DECIMAL_VALUE2, LONG_VALUE1) VALUES (@p0, @p1, @p2); select SCOPE_IDENTITY()’ , N’@p0 decimal(16,5),@p1 decimal(16,5),@p2 bigint’, @p0 = 9.94434, @p1 = 9.94434, @p2 = 5583

Hence, the gotcha is that NHibernate by default sets the SCALE to “5”, if we haven’t told any SCALE in entity mapping class for the particular property.

The reason behind: [NH-1594] – When setting property in hbm type=”Decimal(precision, scale)” – “DECIMAL(19,5)” is always generated Ref: https://github.com/leemhenson/nhibernate/blob/master/nhibernate/releasenotes.txt

Solution: Enforcing scale to “6” in the fluent mapping or .hbm like below, it works great.

Map(x => x.DECIMAL_VALUE1).Scale(6);

<property name=”DECIMAL_VALUE1″ scale=”6″ />

Happy coding!

.NET GAC (Global Assembly Cache) folder location

March 6, 2014

Hope, some of you still think that the default GAC folder is c:\windows\assembly [%windir%\assembly] as such. But there is a BIG “NO”.

Yes, starting with the .NET Framework 4, the default location for the global assembly cache has been changed.

Reference: http://msdn.microsoft.com/en-us/library/yf1d93sz(v=vs.110).aspx

In .NET Framework 4.0, the GAC went through a few changes. The GAC was split into two, one for each CLR. The CLR version used for both .NET Framework 2.0 and .NET Framework 3.5 is CLR 2.0. There was no need in the previous two framework releases to split GAC. The problem of breaking older applications in Net Framework 4.0.

To avoid issues between CLR 2.0 and CLR 4.0, the GAC is now split into private GAC’s for each runtime. The main change is that CLR v2.0 applications now cannot see CLR v4.0 assemblies in the GAC.

.NET 2.0 GAC:

  • c:\windows\assembly – Non-native 32bit and 64bit assemblies.

.NET 4.0 GAC, below are the folders.

  • c:\windows\Microsoft.NET\assembly\GAC_32 – Non-native 32bit assemblies.
  • c:\windows\Microsoft.NET\assembly\GAC_64 – Non-native 64bit assemblies visible only on 64bit Windows.
  • c:\windows\Microsoft.NET\assembly\GAC_MSIL – Non-native MSIL (AnyCPU – 32bit & 64bit) assemblies.

Note:

While trying to load assemblies from the GAC, the CLR first looks at the GAC specific to the platform. If it is unable to find the same, it then moves to the GAC_MSIL.

Happy reading!🙂

 

Navigate to the .NET Framework source online from VS.NET IDE!

February 26, 2014

Most of you knew that Microsoft recently launched a browsable version of the .Net reference source code at http://referencesource-beta.microsoft.com.

This would help great and get us the insight over how all of the .NET code has been written. For example,
if you would want to see how String.IsNullOrEmpty() and String.IsNullOrWhiteSpace() has been implemented, here you go.

public static bool IsNullOrEmpty(String value) {
return (value == null || value.Length == 0);
}

public static bool IsNullOrWhiteSpace(String value) {
if (value == null) return true;

for(int i = 0; i < value.Length; i++) {
if(!Char.IsWhiteSpace(value[i])) return false;
}

return true;
}

Interesting, right!

Reference: Have a look @ Scott Hanselman's blog: http://goo.gl/D9jR6a

Below is the code excerpt from Scott Hanselman’s blog:
BONUS: Community Visual Studio Extension for navigating into the online .NET Framework source from VS.NET IDE.

Here’s an exciting bonus. Community member and fabulous coder Schabse Laks has created a Visual Studio extension for VS2010, 2012, and 2013! This extension sends calls to Go To Definition (or pressing F12 on a symbol) directly to the code online (when it’s .NET Framework code, not yours).

You can download this companion “Ref12” Visual Studio Extension now! Just Goto Definition on any .NET type we have source for and it’ll launch your default browser so you can explore the .NET Framework source yourself! Thanks Schabse!

Enjoy exploring!

Static vs. Singleton Classes – FAQ

February 22, 2014

Just I had gone through an articles over http://java.dzone.com about Static vs. Singleton Classes and related FAQ.Thought of sharing to the wordpress community.

The below excerpt is taken from the link : http://java.dzone.com/articles/singleton-design-pattern-%E2%80%93

FAQs:

Question: Why can’t we use a static class instead of singleton?
Answer:

  • One of the key advantages of singleton over static class is that it can implement interfaces and extend classes while the static class cannot (it can extend classes, but it does not inherit their instance members). If we consider a static class it can only be a nested static class as top level class cannot be a static class. Static means that it belongs to a class it is in and not to any instance. So it cannot be a top level class.
  • Another difference is that static class will have all its member as static only unlike Singleton.
  • Another advantage of Singleton is that it can be lazily loaded whereas static will be initialized whenever it is first loaded.
  • Singleton object stores in Heap but, static object stores in stack.
  • We can clone the object of Singleton but, we can not clone the static class object.
  • Singleton can use the Object Oriented feature of polymorphism but static class cannot.

Question: Can the singleton class be subclassed?
Answer: Frankly speaking singleton is just a design pattern and it can be subclassed. However it is worth to understand the logic or requirement behind subclassing a singleton class as the child class might not inherit the singleton pattern objective by extending the Singleton class. However the subclassing can be prevented by using the final keyword in the class declaration.

Question: Can there be multiple instance of singleton using cloning?
Answer: That was a good catch! What do we do now? To prevent the another instance to be created of the singleton instance we can throw exception from inside the clone() method.

Question: What is the impact if we are creating another instance of singleton using serialization and deserialization?
Answer: When we serialize a class and deserialize it then it creates another instance of the singleton class. Basically as many times as you deserialize the singleton instance it will create multiple instance. Well in this case the best way is to make the singleton as enum. In that way the underlying Java implementation takes care of all the details. If this is not possible then we will need to override the readobject() method to return the same singleton instance.

Question: Which other pattern works with Singleton?
Answer:There are several other pattern like Factory method, builder and prototype pattern which uses Singleton pattern during the implementation.

Question: Which classes in JDK uses singleton pattern?
Answer: java.lang.Runtime : In every Java application there is only one Runtime instance that allows the application to interface with the environment it is running. The getRuntime is equivalent to the getInstance() method of the singleton class.

Enjoy reading.

Courtesy: Mainak Goswami

NHibernate Vs Entity Framework 6.0 – A Comparison

December 3, 2013

Here is a nice comparison table for NHibernate and Entity framework 6.0. This is the result of my searching and reading, to get to know over the evolution of Entity Framework (the latest is V6.0). Enjoy reading!

Feature

NHibernate

EF 1.0 to EF 6.0

Current version

V3.3.3

V 6.0

Year released

 Hibernate (JAVA) 2001/ NHibernate (.NET) 2005

2008

Introduced

.NET 1.1 and above/Mono

.NET Framework 3.5 SP1 and above

Open source

Yes

Yes from 6.0

Associations

Both supports 1 to 1, 1 to many, and many to many

Both supports  1 to 1, 1 to many, and many to many

Rich domain models

Yes

No

Ordered and unordered sets collection. Indexed options. It even has an immutable, indexed list

Yes

No

Mapping private fields (yet) or can you directly use a dictionary class

Yes

No

Collection supports

IDictionary<T,T>  IEnumerable<T>

ICollections

Supporting ENUM

Yes

Yes from 6.0

Vendor support /Providers:

SQL Server/Azure, SQLite, PostgreSQL, Oracle, Sybase, Firebird and DB2

All the DB providers are built-in

SQL Server or SQL Azure,

Code first

Yes

From EF 5.0

Code-based mapping

NHinernate 3.2 with Fluent-NHibernate

From EF 6.0

Supporting custom types and collections

Yes

No

Query flexibility

HQL/QueryOver/Criteria API/Native Vendor specific SQL (3.2 with the above & lot more)

LINQ/Entity SQL/Native SQL/Commercial  provider for ORACLE

Extensibility

Uses Listeners/Configuration properties

ServiceLocator pattern

Async/await support

No

EF 6

Built-in support for automatically reconnecting to the database

No

Yes

.NET 4.5 support

Yes

Yes (with improved performance)

Batch processing

With “Future”

No

Creating a DBContext with an existing open connection

No

Yes

Spatial support

Need 3rd party

In-built

Documentation

Poor, but can get lot of support over forum

Good

Caching

Support second-level caching

Yes from EF6

Events

“NHibernate has a very rich event model, that exposes more than 20 events, either for synchronous pre-execution or asynchronous post-execution”.

Entity Framework only has two event-based extension points: ObjectMaterialized and SavingChanges

Tracking Changes

No

While both default to change tracking at the unit of work level, Entity Framework also offers self-tracking entities.

Able to map SQL views

Yes

No

Querying SSAS OLAP cubes

No

Yes

Interception of queries/object creation

Yes

No

API Methods

Save, Update, SaveOrUpdate, SaveOrUpdateCopy, Replicate and Merge,

 

Lazy loading behavior

One an relationship by relationship basis

For the entire context

Courtesy:

http://dotnet.dzone.com/articles/entity-framework-56-vs

http://weblogs.asp.net/ricardoperes/archive/2012/06/07/differences-between-nhibernate-and-entity-framework.aspx

Misleading exception with .NET DataContractJsonSerializer() – A bug reported to http://connect.microsoft.com/

December 3, 2013
Please find below the complete text from connect.microsoft:
Note: Just copy pasted  as is, so that you may not be finding formatted nicely.🙂
Description
I was working for serializing C# object into JSON using DataContractJsonSerializer(). Whenever the KnownType in not specified in the base class or passed into the constructor of DataContractJsonSerializer(), I have got the following exception.[Exception]
An unhandled exception of type ‘System.Runtime.Serialization.SerializationException’ occurred in System.Runtime.Serialization.dllAdditional information: Type ‘DerivedClasses.CustomerResponse’ with data contract name ‘CustomerResponse:http://schemas.datacontract.org/2004/07/DerivedClasses&#8217; is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types – for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
[/Exception]

Details

Visual Studio/Visual Studio Online/Team Foundation Server/.NET Framework Tooling Version

.NET Framework 4.5.1

What category (if any) best represents this feedback?

Compatibility

Steps to reproduce

1). Have a base class and derived class
2). Don’t mark the base class with [KnownType] attribute
3). Populate derived object with required data
4). Try serializing derived object to JSON using DataContractJsonSerializer(), by passing the typeof(base class)

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

Issues with the exception:The exception what we are getting is as same as for “DataContractSerializer”.

So, this exception message is misleading by saying
1). “Consider using a DataContractResolver”, though DataContractJsonSerializer() is not supporting DataContractResolver.
2). or by adding them to the list of known types passed to “DataContractSerializer”

Expected results

The above two points in “Actual results” section needs to be removed from the exception and to be corrected with specific to “DataContractJsonSerializer”.

Locale

English Connect
Posted by laks_win on 12/2/2013 at 10:49 AM

Hi Team,I have got one more issue on the same Misleading exception with DataContractJsonSerializer() for passing the object which has “Cyclic References”. Actually DataContractJsonSerializer() doesn’t support it, but shows the exception that is specific to DataContractSerializer(). So, please have a check for this issue too.

Thanks and regards
Lakshminarayanan.R

Posted by Microsoft on 11/8/2013 at 2:39 PM

Hi Laks_win.Thank you for the feedback on WCF. This is a good suggestion and we will consider this for a future release.

Thanks,
Erica Mohler
Microsoft Program Manager

Posted by Microsoft on 10/29/2013 at 4:04 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by laks_win on 10/24/2013 at 9:54 PM
Thanks for the follow up. Just uploaded a newly created sample zip, its for your kind perusal.
Posted by Microsoft on 10/24/2013 at 6:22 AM

Thank you for submitting feedback on Visual Studio and .NET Framework. In order to efficiently investigate and reproduce this issue, we are requesting additional information outlined below.Could you please give us a demo project to demonstrate this issue so that we can conduct further research?

We look forward to hearing from you with this information.

Posted by Microsoft on 10/23/2013 at 10:50 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)