:
<connectionStrings>
<add name="DB_PhonebookEntities" connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=DB_Phonebook;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
MyModel.Designer.cs文件中的:
namespace SimplePhoneBook
{
public partial class DB_PhonebookEntities : ObjectContext
{
public DB_PhonebookEntities() : base("name=DB_PhonebookEntities", "DB_PhonebookEntities")
{
....
}
public DB_PhonebookEntities(string connectionString): base(connectionString, "DB_PhonebookEntities")
{
....
}
public DB_PhonebookEntities(EntityConnection connection) : base(connection, "DB_PhonebookEntities")
{
....
}
....
}
如何将Application.StartupPath
设置为我的ConnectionString?
答案 0 :(得分:0)
我希望在应用程序路径上的数据库中创建“模型”(... \ debug \ bin \ database.mdf)
并在我的模型中使用实体!
答案 1 :(得分:0)
将此附加到您的连接字符串。这将指向WebApplication1 \ App_Data。所以你的mdf文件应该在App_Data文件夹中
AttachDBFilename=|DataDirectory|\aspnet-WebApplication1-20141203171438.mdf