简体   繁体   English

实体框架-如何将连接字符串更改为相对?

[英]Entity Framework - how can I change connection string to be relative?

Can someone confirm how to change the auto-generated connection string for an entity framework application so that it is relative? 有人可以确认如何更改实体框架应用程序的自动生成的连接字符串以使其相对吗?

That is so it will work for anyone who downloads and installs the application. 这样一来,它将适用于下载和安装该应用程序的任何人。 That is, currently the connection string auto-generated for me has an absolute path in it. 也就是说,当前为我自动生成的连接字符串中具有绝对路径。 See below for an example: 参见以下示例:

<add name="Model1Container" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SQLite;provider connection string='data source=&quot;C:\Documents and Settings\Owner\My Documents\My Dropbox\source\MyProject\MyProjectLibrary\MyProject.sqlite&quot;'" providerName="System.Data.EntityClient" />

I should note that in my solution the UI application project uses a separate business logic layer project where the Entity Framework model is. 我应该注意,在我的解决方案中,UI应用程序项目使用一个单独的业务逻辑层项目(实体框架模型在其中)。 I have been copying the auto-generated connection string from this latter project to the UI project to get things to work. 我一直在将自动生成的连接字符串从后一个项目复制到UI项目中,以使事情正常进行。

thanks 谢谢

|DataDirectory| | DataDirectory目录| Substitution String from 来自的替换字符串

http://msdn.microsoft.com/en-us/library/cc716756.aspx http://msdn.microsoft.com/en-us/library/cc716756.aspx

You can edit the auto-generated connect string to anything you want. 您可以将自动生成的连接字符串编辑为所需的任何内容。 So long as it's valid, the EF won't care. 只要有效,EF就不会在意。

Perhaps you're really asking "Can SQLLite use a relative connect string?" 也许您真的在问“ SQLLite可以使用相对连接字符串吗?” I don't know, but that has nothing to do with the EF. 我不知道,但这与EF无关。 If it can, the EF will work with it. 如果可以,EF可以使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何关闭实体框架中的连接字符串对象 - How can I close connection string object in Entity Framework .NET Framework 和 Entity Framework Core:如何获取连接字符串 - .NET Framework and Entity Framework Core: How can I get hold of the connection string 如何在web.config中更改实体框架的连接字符串 - How to change connection string in web.config for entity framework 如何动态更改Entity Framework EDMX连接字符串 - How to change Entity Framework EDMX connection string dynamically 如何将连接字符串的绝对路径更改为相对路径? - How can I change my connection string's absolute path to relative path? 更改实体框架中的连接字符串(模型优先) - Change connection string in Entity Framework(Model First) 实体框架:在运行时更改连接字符串 - Entity Framework : Change connection string at runtime Code First Entity Framework - 更改连接字符串 - Code First Entity Framework - change connection string 如何在 Entity Framework Core 中将连接字符串传递给 DBContext? - How do I pass connection string to DBContext in Entity Framework Core? 如何在不处理上下文的情况下刷新Entity Framework连接 - How can I refresh an Entity Framework connection without disposing of the context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM