SELECT publisher,Publisher_Db,publication,article
FROM dbo.MSreplication_objects
where article = 'Table_Name'
FROM dbo.MSreplication_objects
where article = 'Table_Name'
ListOne.Join(ListTwo, (list1) => list1.Id, (list2) => list2.Id, (list1, list2) => | |
{ | |
list1.Name = list2.Name; | |
return list1; | |
}).ToList(); |
CREATE PROCEDURE up_GetTableNameInAllDatabase | |
@TableName VARCHAR(256) | |
AS | |
DECLARE @DataBaseName VARCHAR(256) | |
DECLARE @SQL VARCHAR(512) | |
DECLARE @getDBName CURSOR | |
SET @getDBName = CURSOR FOR | |
SELECT name | |
FROM sys.databases | |
CREATE TABLE #TmpTable (DBName VARCHAR(256), | |
SchemaName VARCHAR(256), | |
TableName VARCHAR(256)) | |
OPEN @getDBName | |
FETCH NEXT | |
FROM @getDBName INTO @DataBaseName | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
SET @SQL = 'USE ' + @DataBaseName + '; | |
INSERT INTO #TmpTable | |
SELECT '''+ @DataBaseName + ''' AS DBName, | |
SCHEMA_NAME(schema_id) AS SchemaName, | |
name AS TableName | |
FROM sys.tables | |
WHERE name LIKE ''%' + @TableName + '%''' | |
EXEC (@SQL) | |
FETCH NEXT | |
FROM @getDBName INTO @DataBaseName | |
END | |
CLOSE @getDBName | |
DEALLOCATE @getDBName | |
SELECT * | |
FROM #TmpTable | |
DROP TABLE #TmpTable | |
GO | |
--EXEC up_GetTableNameInAllDatabase 'TableName_Here' |
using System.Collections.Generic; | |
namespace NSubstitute_Demo | |
{ | |
class DataManager : IDataManager | |
{ | |
public List<int> GetStudentMarks(int studentId) | |
{ | |
//Open connection | |
//Call to DB to get the student marks | |
//Return the student marks | |
return new List<int> { 85, 98, 87, 76, 99, 67 }; | |
} | |
} | |
} |
using System.Collections.Generic; | |
using System.Linq; | |
namespace NSubstitute_Demo | |
{ | |
public class Processor | |
{ | |
IDataManager _dataMgr; | |
public Processor(IDataManager dataMgr) | |
{ | |
_dataMgr = dataMgr; | |
} | |
public double CalculateStudentPercentage(int studentId) | |
{ | |
List<int> marks =_dataMgr.GetStudentMarks(studentId); | |
int percentage = marks.Aggregate((a,b) => (a + b) / marks.Count); | |
return percentage; | |
} | |
} | |
} |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
using NSubstitute; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace NSubstitute_Demo.Tests | |
{ | |
[TestClass()] | |
public class ProcessorTests | |
{ | |
[TestMethod()] | |
public void CalculateStudentPercentageTest() | |
{ | |
//Arrange | |
List<int> mockMarksList = new List<int> { 50, 60, 70, 80, 90, 60 }; | |
double expected = mockMarksList.Aggregate((a, b) => (a + b) / mockMarksList.Count); | |
var substituteDataMgr = Substitute.For<IDataManager>(); | |
substituteDataMgr.GetStudentMarks(1101601306) | |
.ReturnsForAnyArgs(mockMarksList); | |
Processor _processor = new Processor(substituteDataMgr); | |
//Act | |
double actual = _processor.CalculateStudentPercentage(1101601306); | |
//Assert | |
Assert.AreEqual(actual,expected); | |
} | |
} | |
} |
public DataTable ConvertsomeClassTosomeDataTable(List<someClass> someClassObjectList) | |
{ | |
DataTable convertedsomeClassObjectList = new DataTable("SomeDataTable"); | |
// Lest assume we have 3 properties in your someClass Class | |
convertedsomeClassObjectList.Columns.Add("Property1", typeof(int)); | |
convertedsomeClassObjectList.Columns.Add("Property2", typeof(DateTime)); | |
convertedsomeClassObjectList.Columns.Add("Property3", typeof(int)); | |
foreach (someClass obj in someClassObjectList) | |
{ | |
convertedsomeClassObjectList.Rows.Add( | |
obj.Property1, | |
obj.Property2, | |
obj.Property3); | |
} | |
return convertedsomeClassObjectList; | |
} |
public static class Extensions | |
{ | |
public static DataTable ToDataTable<T>(this IList<T> data) | |
{ | |
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T)); | |
DataTable DataTable = new DataTable(); | |
for (int i = 0; i < properties.Count; i++) | |
{ | |
PropertyDescriptor prop = properties[i]; | |
DataTable.Columns.Add(prop.Name, Nullable.GetUnderlyingType( | |
prop.PropertyType) ?? prop.PropertyType); | |
} | |
object[] objectValues = new object[properties.Count]; | |
foreach (T item in data) | |
{ | |
for (int i = 0; i < objectValues.Length; i++) | |
{ | |
objectValues[i] = properties[i].GetValue(item); | |
} | |
DataTable.Rows.Add(objectValues); | |
} | |
DataTable.TableName = typeof(T).Name + "Your Table Name"; | |
return DataTable; | |
} | |
} |
WITH CTE | |
AS | |
( | |
SELECT ROW_NUMBER() OVER (PARTITION BY UserName ORDER BY Id) AS rowNum, | |
Id,UserName FROM Users) | |
DELETE FROM CTE WHERE rowNum > 1 |