2017年10月29日 星期日
How to find LDAP server in Windows via command prompt
How to find LDAP server in Windows
$> nslookup
> set types=all
> _ldap._tcp
How to remove locked USB External drive
To safely remove the drive:
Open Command Prompt (cmd.exe).
Type diskpart.
Type list disk.
Find your disk #, and type select disk [number here].
Type offline disk.
You should be able to remove it now.
Next time you plug it in, it won't be automatically mounted. So either use the command prompt again to make it online, or:
Run diskmgmt.msc.
Find the disk, right click, and choose "Online".
2017年10月26日 星期四
How to identify blocking in SQL Server
How to identify blocking in SQL Server
- Activity Monitor
- SQLServer:Locks Performance Object
- DMVs
- sys.dm_exec_requests
- sys.dm_tran_locks
- sys.dm_os_waiting_tasks
- SQL Server Profiler Locks Event Category
exec sp_who2
select * from sys.dm_tran_locks
SELECT OBJECT_NAME(p.OBJECT_ID) AS TableName, resource_type, resource_description FROM sys.dm_tran_locks l JOIN sys.partitions p ON l.resource_associated_entity_id = p.hobt_id
DBCC inputbuffer (SPID)
USE master; GO KILL spid | UOW [WITH STATUSONLY] GO
DBCC opentran (Database)
2017年10月23日 星期一
How to find duplicate row in SQL
How to find duplicate row in SQL
Single Row
Multiple Row
Single Row
SELECT
[RefID], COUNT(*)
FROM
[myTable]
GROUP BY
[RefID]
HAVING
COUNT(*) > 1
Multiple Row
SELECT
name, email, COUNT(*)
FROM
users
GROUP BY
name, email
HAVING
COUNT(*) > 1
2017年10月19日 星期四
Umbraco Content Service Event Order
Environment
- Umbraco version 7.7.2
- Umbraco version 7.7.2
For Writer
Save and send to Approval
ContentService.SendingToPublish -> ContentService.Saved -> ContentService.SentToPublish
For Editor
Save and Publish
ContentService.Publishing -> ContentService.Saved -> ContentService.Published
2017年10月12日 星期四
How to self-referencing in Entity Framework via Code First
How to self-referencing in Entity Framework via Code First
Environment
- VS 2015
- MVC 5
- .Net Framework 4.6.1
- Code First
- MS SQL 2012 Server
Model Class
User.cs
Context Class
MyContext.cs
Initializer Class
MyInitializer.cs
Environment
- VS 2015
- MVC 5
- .Net Framework 4.6.1
- Code First
- MS SQL 2012 Server
Model Class
User.cs
public class User
{
[Index]
[Key]
public int Id { get; set; }
[Column(TypeName = "nvarchar")]
[StringLength(255)]
[Required]
public string Name { get; set; }
[Column(TypeName = "nvarchar")]
[StringLength(125)]
[Required]
public string Login { get; set; }
[Column(TypeName = "nvarchar")]
[StringLength(500)]
[Required]
public string Password { get; set; }
[Column(TypeName = "bit")]
public bool IsDisabled { get; set; }
[Column(TypeName = "nvarchar")]
[StringLength(255)]
[Required]
public string Email { get; set; }
public int FailedLoginAttempts { get; set; }
public DateTime CreatedOn { get; set; }
public int? CreatedBy { get; set; }
public User Creator { get; set; }
public DateTime ModifiedOn { get; set; }
public int? ModifiedBy { get; set; }
public virtual User Modifier { get; set; }
[Column(TypeName = "bit")]
public bool IsDeleted { get; set; }
}
Context Class
MyContext.cs
public class MyContext : DbContext
{
#region Properties
public DbSet<User> Users { get; set; }
#endregion
#region Ctor
public MyContext() : base("MyContext")
{
}
#endregion
#region Methods
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// Pluralizing
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
// lower camelCase
modelBuilder.Properties().Configure(c =>
{
var name = c.ClrPropertyInfo.Name;
var newName = char.ToLower(name[0]) + name.Substring(1);
c.HasColumnName(newName);
});
// User Table
modelBuilder.Entity<User>()
.HasOptional(e => e.Creator)
.WithMany()
.HasForeignKey(m => m.CreatedBy);
modelBuilder.Entity<User>()
.HasOptional(e => e.Modifier)
.WithMany()
.HasForeignKey(m => m.ModifiedBy);
}
#endregion
}
Initializer Class
MyInitializer.cs
public class MyInitializer : System.Data.Entity.DropCreateDatabaseIfModelChanges<MyContext>
{
protected override void Seed(MyContext context)
{
var systemUser = new User { Name = "System Admin", Login = "System Admin", Password = "1234567890", IsDisabled = false, Email = "admin@admin.com", FailedLoginAttempts = 0, CreatedOn = DateTime.Today, ModifiedOn = DateTime.Today, IsDeleted = false };
context.Users.Add(systemUser);
context.SaveChanges();
var users = new List<User>
{
new User { Name = "Sam", Login = "sam", Password = "1234567890", IsDisabled = false, Email = "sam@sam.com", FailedLoginAttempts = 0, Creator=systemUser, CreatedOn = DateTime.Today, Modifier=systemUser, ModifiedOn = DateTime.Today, IsDeleted = false },
new User { Name = "Peter", Login = "peter", Password = "1234567890", IsDisabled = false, Email = "peter@peter.com", FailedLoginAttempts = 0, Creator=systemUser, CreatedOn = DateTime.Today, Modifier=systemUser, ModifiedOn = DateTime.Today, IsDeleted = false },
};
users.ForEach(s => context.Users.Add(s));
context.SaveChanges();
}
}
Result in SQL Server
訂閱:
文章 (Atom)
