Monday 22 September 2014

Fast way of deleting large amounts of files

he worst way is to send to Recycle Bin: you still need to delete them. Next worst is shift+delete with Windows Explorer: it wastes loads of time checking the contents before starting deleting anything.
Next best is to use rmdir /s/q foldername from the command line. del /f/s/q foldername is good too, but it leaves behind the directory structure.
The best I've found is a two line batch file with a first pass to delete files and outputs to nul to avoid the overhead of writing to screen for every singe file. A second pass then cleans up the remaining directory structure:
del /f/s/q foldername > nul
rmdir /s/q foldername
This is nearly three times faster than a single rmdir, based on time tests with a Windows XP encrypted disk, deleting ~30GB/1,000,000 files/15,000 folders: rmdir takes ~2.5 hours, del+rmdir takes ~53 minutes. More info at Super User.
This is a regular task for me, so I usually move the stuff I need to delete to C:\stufftodelete and have those del+rmdir commands in a deletestuff.bat batch file. This is scheduled to run at night, but sometimes I need to run it during the day so the quicker the better.


Answer is taken from:
http://stackoverflow.com/questions/186737/whats-the-fastest-way-to-delete-a-large-folder-in-windows

Friday 12 September 2014

EF does not search on nullable field

Search for database entries with null fields


Configuration of the EF does have bearing on the implementation.

Consider case:

   public CustomerMap()
        {
            // Primary Key
            this.HasKey(t => t.CustomerId);

            // Properties
            this.Property(t => t.Name)
                .IsRequired()
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("Customers");
            this.Property(t => t.CustomerId).HasColumnName("CustomerId");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.UserId).HasColumnName("UserId").IsRequired();
        }

this will never work with the query

    context.Customers.Where(x=>x.UserId==null)

nor with

    context.Customers.Where(x=>!x.UserId.HasValue)

this is because of incorrect mapping:

    this.Property(t => t.UserId).HasColumnName("UserId").IsRequired();

Solution:


Mapping configuration has to be changed to

    this.Property(t => t.UserId).HasColumnName("UserId").IsOptional();

or remove it all together, this depends on version of EF

    this.Property(t => t.UserId).HasColumnName("UserId");