12.13.2012

EF Code First Migrations Error on Foreign Key Constraints

Got this error message: Introducing FOREIGN KEY constraint 'FK_dbo.Emails_dbo.Certificates_CertificateId' on table 'Emails' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.

SOLUTION: Change the Up Method of the migration on the ForeignKey field as follows:
.ForeignKey("dbo.Creators", t => t.SenderId, cascadeDelete: false)
.ForeignKey("dbo.Certificates", t => t.CertificateId, cascadeDelete: false)
Change cascadeDelete to false.

11.29.2012

How to Install Windows Service in Server 2008

1.  Open command as administrator
2.  Go to C:\Windows\Microsoft.NET\Framework64\v2.0.50727
3.  Install service:
C:\Windows\Microsoft.NET\Framework64\v2.0.50727>installutil MyNewService.exe
4.  Go to Services: services.msc in cmd and then start the service.
5.  To uninstall.  First stop the service, then do:
C:\Windows\Microsoft.NET\Framework64\v2.0.50727 installutil /u MyNewService.exe

11.19.2012

Cannot truncate table because it is being referenced by a FOREIGN KEY

This would have the same effect as truncate, minus the warning...(be careful, this also deletes all the data of the table referencing this table)
DELETE FROM dbo.Creators DBCC CHECKIDENT ('dbo.Creators',RESEED, 0)

11.16.2012

Set Up Code First Migrations for EF in ASP.NET MVC 4

First open Package Manager Console: Tools > Library Package Manager > Package Manager Console

1.  Go to the project, either the Web Application or if a separate project for Model, then enable the migration as follows:
PM> Enable-Migrations -ContextTypeName ProductCoC.Model.DataContext
This creates a Migration folder within the project root and creates the initial creation classes as well as the Configuration.cs.  Open Configuration.cs and add your seed.

2.  Initialize
PM> Add-Migration Initial
3.  Now, let's update the database:
PM> update-database
4.  If adding a property to the model classes, change the model class then do an add as follows, any arbitrary name will do:
PM> add-migration AddSoldToPartyAndShipToParty
5.  Now do a database update:
PM> update-database

8.01.2012

Visual Studio files and directories that should be in source control ignore list

1.  Solution user option files (*.suo).
2.  Project user option files (*.csproj.user)
3.  Web information files (*.csproj.webinfo)
4.  Bin directory
5.  Obj directory

6.21.2012

How to put project in SVN for the first time

1.  Create a new repository on the server.
2.  Create a directory on local computer.  In that directory, execute the following:
svn checkout --username myuser https://www.collabnet.company.com/svn/projectname
This checkouts the empty repository on the directory created.

3.  Copy the files to checkin into this directory.  Then add everything:
svn add *
4.  Lastly, commit:
svn commit -m "Initial Import"
SVN Basic Work Cycle: http://svnbook.red-bean.com/nightly/en/svn.tour.cycle.html#svn.tour.cycle.update
SVN Cheat Sheet: http://www.abbeyworkshop.com/howto/misc/svn01/

5.04.2012

SharePoint 2010 PowerShell Commands

Add Windows PowerShell snap-in
sp> Add-PSSnapin microsoft.sharepoint.powershell
Load SPListFunctions (download from here)
sp> . .\SPListFunctions.ps1
Return all Lists
sp> Get-SPLists -url http://usbtmp8375msdev:9342/
Return information on specific list
sp> Get-SPList -url http://usbtmp8375msdev:9342/NDAGenerator/ -title "NDA Contents"