我在学习SQL Azure时按照这个教程顺利完成了: Windows Azure教程
我想创建一个类似的应用程序,但使用代码优先方法实现一个更复杂的数据库,并在键入“update-database”命令时收到以下错误:
Cannot attach the file 'c:\users\dadler\documents\visual studio 2012\Projects\EliteTrainingAzure\EliteTrainingAzure\App_Data\EliteTrainingAzure.Models.EliteTrainingDB.mdf' as database 'EliteTrainingAzure.Models.EliteTrainingDB'.
这是我的连接字符串:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-EliteTrainingAzure-20130325095843;User Intance = True;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-EliteTrainingAzure-20130325095843.mdf" providerName="System.Data.SqlClient"/>
最后,这是我如何处理外键创建的示例:
namespace EliteTrainingAzure.Models
{ public class Client { [Key] public int ClientID { get; 放; }
public int GoalID { get; set; }
[ForeignKey("GoalID")]
public Goal Goal { get; set; }
public int TrainerID { get; set; }
[ForeignKey("TrainerID")]
public Trainer Trainer { get; set; }
public string ClientName {get; set;}
public string ClientAddress { get; set; }
public string ClientCity { get; set; }
public string ClientState { get; set; }
public string ClientZip { get; set; }
如果有人能指出我如何解决这个错误的正确方向,那就太好了。提前致谢!