In SQL Server, how can I lock a single row in a way similar to Oracle’s “SELECT FOR UPDATE WAIT”?

You’re probably looking forwith (updlock, holdlock). This will make a select grab an exclusive lock, which is required for updates, instead of a shared lock. The holdlock hint tells SQL Server to keep the lock until the transaction ends. FROM TABLE_ITEM with (updlock, holdlock)

Upload CSV file to SQL server

1st off, You don’t need programming stuff. You can directly upload CSV files into SQL Database with SQL management tools. However, if you really need do it through programming, Just read below. Personally, I think this approach is the most efficient and easiest way to do through programming. In general, you can achieve it in … Read more

How to Specify Primary Key Name in EF-Code-First

If you want to specify the column name and override the property name, you can try the following: Using Annotations public class Job { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] [Column(“CustomIdName”)] public Guid uuid { get; set; } public int active { get; set; } } Using Code First protected override void OnModelCreating(DbModelBuilder mb) { base.OnModelCreating(mb); mb.Entity<Job>() .HasKey(i => … Read more

Is there a .NET equivalent to SQL Server’s newsequentialid()

It should be possible to create a sequential GUID in c# or using an API call to UuidCreateSequential. The API declaration (C#) below has been taken from where you can also find a full example of how to call the function. [DllImport(“rpcrt4.dll”, SetLastError=true)] static extern int UuidCreateSequential(out Guid guid); The MSDN article related … Read more