Why would scaffolding in the Beta generate the controller actions differently? If I change (Guid id = null) to (Guid id) like scaffolding did before installing the Beta it works fine.
Reporting by definition is different. Otherwise we would just show it on the screen.
Right, so fix it. It's an awesome error message. It's beta software. I opened a bug, it should be addressed by the next version. The scaffolder is not perfect, it's meant to get you started.
ryanbesko
Contributor
3551 Points
619 Posts
MVC 4, Entity Framework Code-First, Guid Primary Key, Scaffolding
Feb 29, 2012 06:07 PM|LINK
I started playing with MVC 4 Beta today.
I have this simple class for my model:
public class Association { public Guid AssociationId { get; set; } }And this simple class for my context:
public class BillingContext : DbContext { public DbSet Associations { get; set; }
; protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>()
}
}
When I create a new Association controller using scaffolding, it creates these actions in the AssociationController:
// // GET: /Association/Details/5 public ActionResult Details(Guid id = null) { Association association = db.Associations.Find(id); if (association == null) { return HttpNotFound(); } return View(association); } // // GET: /Association/Edit/5 public ActionResult Edit(Guid id = null) { Association association = db.Associations.Find(id); if (association == null) { return HttpNotFound(); } return View(association); } // // GET: /Association/Delete/5 public ActionResult Delete(Guid id = null) { Association association = db.Associations.Find(id); if (association == null) { return HttpNotFound(); } return View(association); }The part (Guid id = null) that is on each of these actions gives this error in Visual Studio:
"A value of type '<null>' cannot be used as a default parameter because there are no standard conversions to type 'System.Guid'."
Before installing the Beta using scaffolding gave me these actions in the AssociationController:
// // GET: /Association/Details/5 public ViewResult Details(Guid id) { Association association = db.Associations.Find(id); return View(association); } // // GET: /Association/Edit/5 public ActionResult Edit(Guid id) { Association association = db.Associations.Find(id); return View(association); } // // GET: /Association/Delete/5 public ActionResult Delete(Guid id) { Association association = db.Associations.Find(id); return View(association); }These actions work just fine.
So, what's up with (Guid id) in the working controllers now being (Guid id = null) in the not-working controllers? Am I missing something?
Thanks in advance for any suggestions.
ricka6
All-Star
15070 Points
2272 Posts
Microsoft
Moderator
Re: MVC 4, Entity Framework Code-First, Guid Primary Key, Scaffolding
Feb 29, 2012 06:24 PM|LINK
Excellent error message
"A value of type '<null>' cannot be used as a default parameter because there are no standard conversions to type 'System.Guid'."
That says it all. Your old version is not setting the default value to null. Maybe you should set the default to a GUID of all 0's.
ryanbesko
Contributor
3551 Points
619 Posts
Re: MVC 4, Entity Framework Code-First, Guid Primary Key, Scaffolding
Feb 29, 2012 06:31 PM|LINK
Why would scaffolding in the Beta generate the controller actions differently? If I change (Guid id = null) to (Guid id) like scaffolding did before installing the Beta it works fine.
ricka6
All-Star
15070 Points
2272 Posts
Microsoft
Moderator
Re: MVC 4, Entity Framework Code-First, Guid Primary Key, Scaffolding
Feb 29, 2012 06:36 PM|LINK
Using default params is more robust. Perhaps it should check when the param is a GUID
ryanbesko
Contributor
3551 Points
619 Posts
Re: MVC 4, Entity Framework Code-First, Guid Primary Key, Scaffolding
Feb 29, 2012 06:55 PM|LINK
What should check when the param is a Guid? Scaffolding? That's what generated everything.
ricka6
All-Star
15070 Points
2272 Posts
Microsoft
Moderator
Re: MVC 4, Entity Framework Code-First, Guid Primary Key, Scaffolding
Feb 29, 2012 06:56 PM|LINK
Right, so fix it. It's an awesome error message. It's beta software. I opened a bug, it should be addressed by the next version. The scaffolder is not perfect, it's meant to get you started.
ryanbesko
Contributor
3551 Points
619 Posts
Re: MVC 4, Entity Framework Code-First, Guid Primary Key, Scaffolding
Feb 29, 2012 07:01 PM|LINK
Thank you for your help. I will fix it myself. Also, thank you for confirming it is a bug, not something I'm doing wrong.
ricka6
All-Star
15070 Points
2272 Posts
Microsoft
Moderator
Re: MVC 4, Entity Framework Code-First, Guid Primary Key, Scaffolding
Feb 29, 2012 07:46 PM|LINK
Thanks for reporting it.