Thursday, December 10, 2015

SQL query to LinQ sub query simple tricks


I have the following SQL query and I will change it in LINQ, Simple query but have to do in one query to reduce database call. Here is the SQL query
select * from td_Accountline 
where 
    BonusPlanID = 1
    and Amount > 0
    and Ord_Sub_ID like '%SMPORD%' 
    and MONTH(Created) = 11
    and YEAR(Created) = 2013  
    and Ord_Sub_ID not in (
        select Ord_Sub_ID 
        from td_Accountline 
        where 
            BonusPlanID =3 and
            Ord_Sub_ID like '%SMPORD%'
    ) 

My LinQ query is bellow, I have used 'let'. The 'Let' keyword allows storing the results of a query which can be used in a subsequent query.
  var accountdata = from acc in currentDatabase.td_Accountline 
                    where
                    acc.BonusPlan.BonusPlanID == 1
                    && acc.Amount > 0
                    && acc.Ord_Sub_ID.Contains("SMPORD")
                    && acc.Created.Value.Month == 11
                    && acc.Created.Value.Year == 2015
                    let accNot = from accN in currentDatabase.td_Accountline 
                                 where
                                 accN.BonusPlan.BonusPlanID == 3
                                 && accN.Ord_Sub_ID.Contains("SMPORD")
                                 select accN.Ord_Sub_ID
                             where !accNot.Contains(acc.Ord_Sub_ID)
                    select acc;


Happy LinQ Sub Query :)

Thursday, March 12, 2015

Asp .net MVC hidden field can't set value using jquery [Solved]

My hidden field is declared like this:
@Html.HiddenFor(model => model.Token, new { ClientIDMode = "Static" })

Then assign the value bellow way in hidden field
 var token = response.id;                    
 $('#Token').val(token);

Mention: You have to Set ClientIDMode="Static" and then you can use $('#Token').val(token); to set the value in asp.net hidden

Happy programming !

Wednesday, March 4, 2015

Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0 [Solved]

When I am working on mvc application using vs2013 and windows 8.
I got this bellow error messsage :

Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

[Solved]

I fixed this issue bellow way:
Project-->Manage Nuget Package-->Updates --> nuget.org-->Update All

Monday, February 16, 2015

How to find the Second value (could be largest or lowest) from a table.?


I have One table with StatusIDHeld in "UserStatusHistory"Table with this column userid,StatusIDHeld and statusChangedOn. One customer could be multiple StatusIDHeld . I am finding out just previous one StatusIDHeld that mean the second StatusIDHeld which just before he had hold.

To be able to get 1., 2. or n-th record depending on sort order, use ROW_NUMBER() function.
                        SELECT StatusIDHeld 
   FROM
   (
    SELECT StatusIDHeld, ROW_NUMBER () OVER(order by statusChangedOn DESC) as RowNo
    FROM UserStatusHistory where userid= 1037146 
   ) AS t
   where t.RowNo = 2


Happy Query .....

SQL SERVER – Simple Example of Cursor with update table

A cursor is a set of rows together with a pointer that identifies a current row.

DECLARE cursor_activatedOnEmpty CURSOR FOR SELECT userid, statusid,RegisteredOn, activatedOn, RealActivationDate FROM UserProfile where statusID=1330 and  activatedOn is null; 
DECLARE @userid INT;
DECLARE @statusid INT;
DECLARE @RegisteredOn Date;
DECLARE @activatedOn Date;
DECLARE @RealActivationDate Date;
DECLARE @PreviousStatusID INT;
OPEN cursor_activatedOnEmpty;
FETCH NEXT FROM cursor_activatedOnEmpty INTO @userid, @statusid,@RegisteredOn, @activatedOn,@RealActivationDate;
WHILE @@FETCH_STATUS = 0  
BEGIN    
 
 SET @PreviousStatusID = (select top 2 StatusIDHeld from dbo.UserStatusHistory where userid=@userid order by statusChangedOn DESC)  
       if (@PreviousStatusID=1325)
       update UserProfile set activatedOn=@RegisteredOn where userid=@userid

       FETCH NEXT FROM cursor_activatedOnEmpty INTO @userid, @statusid,@RegisteredOn, @activatedOn,@RealActivationDate;
END;
CLOSE cursor_activatedOnEmpty;
DEALLOCATE cursor_activatedOnEmpty;

Happy Cursor!!

Sunday, February 8, 2015

Complex Json deserialization C# (class is not supported for deserialization of an array)


I am trying to deserialization array bellow this way.
This is my json file.
[
   [
      {
         "name":"Riaz Kabir",
         "url":"https://recruit.theladders.com/resumeviewer?jobseekerId=01-sid-BDLBKUPMIL6HGZ22MOAJJIWYGE",
         "summary":"ASP.NET MVC Developer Hewlett-Packard (HP) (1/2013-Present) Location: Schenectady, NY Compensation: $50k+ Previous Titles/Companies: 2016 ►",
         "role":"ASP.NET MVC Developer at Hewlett-Packard (HP)",
         "compensation":"$50k+",
         "education":"BS, Computer Science and Engineering, Asian University of Bangladesh",
         "expertise":"Databases , IT Consulting , Software Development , Front End Development",
         "years":"Less than 5",
         "relocation":"Schenectady, NY Within 1000 miles of 12305 Would need to relocate here",
         "resume":"0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAP",
         "resumeExtension":"doc",
         "resumeMimeType":"application/msword"
      }
   ]
]

Bellow my candidate Resume class
public class CandidateResume
        {

            public string name { get; set; }
            public string url { get; set; }
            public string summary { get; set; }
            public string role { get; set; }
            public string compensation { get; set; }
            public string education { get; set; }
            public string expertise { get; set; }
            public string years { get; set; }
            public string relocation { get; set; }
            public string resume { get; set; }
            public string resumeExtension { get; set; }
            public string resumeMimeType { get; set; }

        }

I have bind this "WebScrappingCandidate" class this bellow way.
                JavaScriptSerializer jsSerializer = new JavaScriptSerializer() { MaxJsonLength = 86753090 };
                List> myobj = jsSerializer.Deserialize>>(description);

                foreach (List listCandidateResume in myobj)
                {
                    foreach (CandidateResume candidateResume in listCandidateResume)
                    {
                        WebScrappingCandidate webScrappingCandidate = new WebScrappingCandidate();
                        webScrappingCandidate.FullName = candidateResume.name;
                        webScrappingCandidate.ResumeUrl = candidateResume.url;
                        webScrappingCandidate.Summary = candidateResume.summary;
                        webScrappingCandidate.PositionName = candidateResume.role;
                        webScrappingCandidate.Compensation = candidateResume.compensation;
                        webScrappingCandidate.Education = candidateResume.education;
                        webScrappingCandidate.Skills = candidateResume.expertise;
                        webScrappingCandidate.YearsOfExperience = candidateResume.years;
                        webScrappingCandidate.Relocation = candidateResume.relocation;                        
                        webScrappingCandidate.ResumeText = candidateResume.resume;                                                                  
                    }                                       
                }   

Happy Programming :)