Data Binding

Oct 10, 2012 at 8:52 PM

Hi,

How does the database know what fields to bind to?

 

My Table:

productID

product_name

product_desc

 

My Entity

public Guid ProductID

public string Name

public string Description

 

How would the database know to map productID -> ProductID

 

Thanks,

Coordinator
Oct 10, 2012 at 10:34 PM
Entity Framework Code First uses some documented conventions to match properties to table columns. These are documented here: http://msdn.microsoft.com/en-US/data/jj679962

So for instance, it will automatically map the ProductID item to the productID column since the names match (not case sensitive) and it knows it's the primary key: "Code First infers that a property is a primary key if a property on a class is named “ID” (not case sensitive), or the class name followed by "ID". If the type of the primary key property is numeric or GUID it will be configured as an identity column."

For cases where the property and column don't match, you can [Table] and [Column] data annotation attributes as described here: http://msdn.microsoft.com/en-us/data/jj591583


From: no1_melman
Sent: Wednesday, October 10, 2012 1:52 PM
To: Jon Galloway
Subject: Data Binding [mvcmusicstore:398883]

From: no1_melman

Hi,

How does the database know what fields to bind to?

My Table:

productID

product_name

product_desc

My Entity

public Guid ProductID

public string Name

public string Description

How would the database know to map productID -> ProductID

Thanks,

Oct 12, 2012 at 8:58 AM

Thank you very much for your reply, extremely helpful

 

Thanks,