This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DbMigrationExtensions | |
{ | |
public static void AlterDataFileSize(this DbMigration dbMigration, int size) | |
{ | |
var sqlMethod = dbMigration.GetType().GetMethod("Sql", BindingFlags.Instance | BindingFlags.NonPublic); | |
sqlMethod.Invoke(dbMigration, new object[] { $@" | |
DECLARE @dbName varchar(100) = (SELECT db_name()) | |
DECLARE @sqlCommand nvarchar(1000) = ('ALTER DATABASE ' + @dbName + ' MODIFY FILE ( NAME = ''' + @dbName +''', SIZE = {size}MB )') | |
EXECUTE sp_executesql @sqlCommand, N'@dbName varchar(100)', @dbName = @dbName | |
", true, null }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GenericCollection<T> : ICollection<T> | |
{ | |
private readonly HashSet<T> _set; | |
public IEnumerator<T> GetEnumerator() | |
{ | |
return _set.GetEnumerator(); | |
} | |
IEnumerator IEnumerable.GetEnumerator() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
var ret1 = ServiceFactory.BaseInfoService.Instance.GetData(15); | |
ServiceFactory.BaseInfoService.SetClientContext(new ClientContext(332, 13)); | |
var ret2 = ServiceFactory.BaseInfoService.Instance.GetData(1055); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// disable select cast(serverproperty('EngineEdition') as int) | |
/// <summary> | |
/// DbConfiguration | |
/// </summary> | |
public class CustomConfiguration : DbConfiguration | |
{ | |
public CustomConfiguration() | |
{ | |
SetDatabaseInitializer<DbContext>(null); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class GhamariDate | |
{ | |
private const decimal GREGORIAN_EPOCH = 1721425.5M; | |
private const decimal ISLAMIC_EPOCH = 1948439.5M; | |
public static string MiladiToGhamari(DateTime date) | |
{ | |
var result = j_gh(date.Year, date.Month, date.Day); | |
return string.Format("{0}/{1}/{2}", result[0], result[1], result[2]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DbContextExtensions | |
{ | |
public static string GetMigrationHistoryModel(this DbContext dbContext) | |
{ | |
var modelBase64 = dbContext.Database.SqlQuery<string>(@" | |
DECLARE @binaryContent VARBINARY(MAX); | |
SELECT @binaryContent = Model FROM [__MigrationHistory]; | |
SELECT CAST('' AS XML).value( 'xs:base64Binary(sql:variable(''@binaryContent''))', 'varchar(max)' ) AS base64Content;" | |
).FirstOrDefault(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Ex | |
{ | |
public static T CopyFrom<T>(this T objTarget, T objSource) | |
{ | |
var typeSource = objSource.GetType(); | |
var propertyInfo = typeSource.GetProperties(); | |
foreach (var property in propertyInfo.Where(property => property.CanWrite)) | |
{ | |
if (property.PropertyType.IsPrimitive()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://jasondentler.com/blog/2010/01/exploiting-context_info-for-fun-and-audit/ | |
DECLARE @Ctx varbinary(128) | |
SELECT @Ctx = CONVERT(varbinary(128), 'Arman') | |
SET CONTEXT_INFO @Ctx | |
DECLARE @CtxData varchar(128) | |
SELECT @CtxData = CONVERT(VarChar(128), CONTEXT_INFO()) | |
PRINT @CtxData |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var binding = new BasicHttpBinding(); | |
var address = new EndpointAddress("http://localhost:65182/TestService.svc"); | |
var factory = new ChannelFactory<ITestService>(binding, address); | |
var channel = factory.CreateChannel(); | |
Console.WriteLine("Result: {0}", channel.DoWork(2, 3)); | |
Console.ReadKey(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE [Valieasr_336_17] | |
GO | |
WITH RowNumbers AS | |
( | |
select *, | |
RowNum = 10000000 + row_number() OVER ( order by Id ) | |
from [Person].[Persons] | |
) | |
UPDATE RowNumbers |