Create Fake Query in LINQ to avoid unknown return type error while drag and drop sp in dbml

In this tutorial you will learn how to create Fake Query in LINQ to avoid unknown return type error while drag and drop sp in dbml. Now many of you will be thinking what does it means? Let me explain you, using linq when you drag and drop stored procedure in dbml file and get following alert then it means LINQ is unable to create class of your stored procedure in designer.cs (dbml). unknown return type
When you can face this problem?
  • When you will be selecting columns based on conditions, means in one condition you are getting five columns and in other conditions you are getting seven columns
  • When you will use temporary tables in stored procedure.
  • In string based stored procedure.
Note:-
You can face this problem only in those SPs in which you are retrieving records. So if LINQ will not generate class of your stored procedure then it means you cannot retrieve records.

Steps to get rid of this problem and to create fake query
  • After getting aforementioned error, you have to delete stored procedure from your dbml file.
  • You have to alter SP, comment whole code written in SP, write fake query, in that fake query you have to mention all columns that you want to retrieve in SELECT command in a way illustrated in following picture


Original SP



Comment the original SP, Write Fake Query and Alter the SP

Execute the SP, it will give you result
Once SP is altered with fake query, drag and drop SP again in dbml file, now this time you will not get any error and class of the SP will be created in designer.cs. In the last you have to alter the SP again but this time you will have to revert the whole SP, comment the Fake Query code and bring back the SP into its original state that it has before the Fake Query. After this alteration in SP there is no need to drag and drop it again.



There is one more thing that I will need to discuss with you guys in next post about fake query which is very important. So stay tuned. So that's it. Cheers!!!!
Read more...

Unable to work on visual studio after windows update installed, visual studio close automatically

Hay guys I faced a problem couple of days ago and then I thought it may come to you guys too so that’s why I am publishing this post. Basically when I installed windows 7 in my system and then installed visual studio 2012 in it. Everything was going smoothly and then interval came :) I installed the windows update and when I tried to open the project in visual studio then it was giving me nasty error and closed automatically.
It was very strange situation for me, I quickly came to a point that it happen due to installation of windows update, I goggled my problem and found solution. Solution is pretty simple, just have to install updates of Visual Studio 2012 which is Microsoft Visual Studio 2012 (KB2781514). I went to this link and download the aforementioned visual studio update. Basically that updates contain patch which is patch_KB2781514.exe, you just have to run the exe and once patch successfully install then open the visual studio and do your work :) No need to restart the system.
Read more...

Split string by multiple character delimiter in asp.net

In this article you will learn how to split string by multiple character delimiter in asp.net. Well it is very simple and we can do it by using the built-in split () function of asp.net. Let's have a look on its implementation.
 
        string actualURL = "http://mywebsite.com/aboutus.aspx/images/test.aspx";
        string[] parts1 = actualURL.Split(new string[] { ".aspx" }, StringSplitOptions.None);

So that's it. In this example we have a wrong url containing two pages name and we have to get the first page so we have split the url by ".aspx" delimeter and store the result in parts1 array. 

Another method to do this task is by using Regex
 
string[] parts2 = Regex.Split(actualURL, @".aspx");

Note: Make sure to use using System.Text.RegularExpressions for using Regex.

Happy Coding!!!
Read more...