Thursday, May 30, 2013

Inheritance in Entity Framework Code First

public abstract class Person
{
     public int PersonID { get; set; }
     public string Name { get; set; }
}
 
public class StaffMember : Person
{
     public string BadgeNumber { get; set; }
     [ForeignKey("StaffMemberID")]
     public virtual ICollection Appointments { get; set; }
}
 
public class Client : Person
{
     [ForeignKey("ClientID")]
     public virtual ICollection Appointments { get; set; }
}
 

public class MyContext : DbContext
{
     public DbSet People { get; set; }
     protected override void OnModelCreating(DbModelBuilder modelBuilder)
     {
          base.OnModelCreating(modelBuilder);
     }
 
     public void Seed(MyContext context)
     {
          Client c1 = new Client { Name = "Steve Client" };
          StaffMember sm1 = new StaffMember { Name = "Staff 1", BadgeNumber = "1234" };
          StaffMember sm2 = new StaffMember { Name = "Staff 2", BadgeNumber = "5678" };
 
          context.People.Add(c1);
          context.People.Add(sm1);

          context.SaveChanges();
      }
 
      public MyContext()
      {
           Database.SetInitializer(new DropCreateDatabaseAlways());
           this.Seed(this);
      }
}


http://sgordondeveloper.blogspot.ca/2013/02/model-inheritance-with-relationship-in.html

Friday, May 24, 2013

What's the difference between IFrame and Frameset?

Frameset is dead and long live iframe :)
Frameset replace body elment. And ifeame can be anywhere in the body. Also frameset is NOT supported in HTML 5

http://www.w3.org/TR/html401/frameset.dtd

Wednesday, May 22, 2013

How to insert BLOB data into database by SQL script?

SELECT ThumbnailPhoto.*, null, null, N'tricycle_pink.gif'
FROM OPENROWSET
(BULK 'c:\images\tricycle.jpg', SINGLE_BLOB) ThumbnailPhoto

Tuesday, May 21, 2013

How to add jQuery reference into ASP.NET MVC 4 project?



@Scripts.Render("~/bundles/jquery")

How to solve "Access is denied" problem in new ASP.NET MVC 4 project?

- Press F4 on the MVC project to open project property window
- Change "Windows Authentication" from "Disabled" to "Enabled"


Error message

Server Error in '/' Application.
Access is denied.


Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.

Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server. Contact the Web server's administrator for additional assistance.