Thursday 27 October 2016

copy array

 // Array.Copy(a, 1, b, 0, 3);
                            // a = source array
                            //1 = start index in source array
                            //b = destination array
                            //0 = start index in destination array
                            //3 = elements to copy

Tuesday 25 October 2016

check duplicate records in list c#


var duplicateCount = campaignDtoList.Select(x => x.CampaignId).GroupBy(n => n).Any(c => c.Count() > 1);



NOTE:   duplicateCount  is return bool value

get table count in sql server

SELECT COUNT(*) from information_schema.tables
WHERE table_type = 'base table'

add range in List C#

public List<EmpDto> GetEmps()
        {
            var empDtoList = new List<EmpDtoList>();
            using (_dbContextScopeFactory.Create(connectionString))
            {
                var empEntity = _empRepository.GetAll();
                empDtoList .AddRange(empEntity .Select(x => new EmpDto
                {
                    Id = x.Id,
                    Name = x.Name,
                    Description = x.Description,
                  
                }));
            }
            return empDtoList ;
        }

Friday 21 October 2016

update order in sql

with EmpUpdate as (

select Employee.*,

row_number() over (partition by  empId

order by SRNumber

) as seqnum

from Employee

)

update EmpUpdate

set EmpOrder =seqnum

where seqnum > 0;

Monday 17 October 2016

contain list in C#

//var valueIdM = existingValueList.Where(e=>splitedValue.Contains(e.CustomFieldValueName))

// .Select(y => y.CustomFieldValueId).ToArray();

//var abc = string.Join(",", valueIdM);

//answereValue = "[" + abc + "]";

Tuesday 4 October 2016

get file name in C#

/// <summary>
    /// Get the extension from the given filename
    /// </summary>
    /// <param name="fileName">the given filename ie:abc.123.txt</param>
    /// <returns>the extension ie:txt</returns>
    public static string GetFileExtension(this string fileName)
    {
        string ext = string.Empty;
        int fileExtPos = fileName.LastIndexOf(".", StringComparison.Ordinal);
        if (fileExtPos >= 0)
            ext = fileName.Substring(fileExtPos, fileName.Length - fileExtPos);
        return ext;
    }

Monday 3 October 2016


private int?  GetCountryIdByCountryName(int countryName)
{

int? countryId= Country!= null ? (int?)Country.Id: null;
return countryId
}