C# 实体数据源连接字符串作为变量
如何从codebehind页面中的变量集设置实体数据源连接字符串 e、 g.在代码背后类似这样的东西C# 实体数据源连接字符串作为变量,c#,asp.net,entity-framework,C#,Asp.net,Entity Framework,如何从codebehind页面中的变量集设置实体数据源连接字符串 e、 g.在代码背后类似这样的东西 string edsconstring = "name=EDSEntities"; 然后在aspx中 <asp:EntityDataSource ID="UnAuthPricesEDS" runat="server" ConnectionString=<%= this.edsconstring %> DefaultContainerN
string edsconstring = "name=EDSEntities";
然后在aspx中
<asp:EntityDataSource ID="UnAuthPricesEDS" runat="server"
ConnectionString=<%= this.edsconstring %> DefaultContainerName="CS3Entities"
EnableFlattening="False" EntitySetName="CustomersItems" Where="it.Authorised=false"
OrderBy="it.DateSet" >
</asp:EntityDataSource>
对于您的案例,请尝试使用CodeExpressionbuilder 添加此类:
[ExpressionPrefix("Code")]
public class CodeExpressionBuilder : ExpressionBuilder {
public override CodeExpression GetCodeExpression(BoundPropertyEntry entry,
object parsedData, ExpressionBuilderContext context) {
return new CodeSnippetExpression(entry.Expression);
}
}
ASPX标记:[观察ConnectionString=”“
]
以便您可以参考web.config中“新建连接字符串”部分中定义的连接字符串。这在使用新的声明性数据控件时非常有用:
<asp:EntityDataSource ID="UnAuthPricesEDS" runat="server"
ConnectionString="<%$ ConnectionStrings: MyConfigConnectionString %>" DefaultContainerName="CS3Entities"
EnableFlattening="False" EntitySetName="CustomersItems" Where="it.Authorised=false"
OrderBy="it.DateSet" >
</asp:EntityDataSource>
I get“服务器标记不能包含构造”。将其更改为public string edsconstring=“name=edsenties”代码>我仍然得到“服务器标记不能包含构造”。即使使用公共字符串,也不支持这样的保留引号ConnectionString=“”
关键字:“Venkata,我的字符串在此解决方案中位于何处?请参阅我已更新了CodeExpressionbuilder
<asp:EntityDataSource ID="UnAuthPricesEDS" runat="server"
ConnectionString="<%$ ConnectionStrings: MyConfigConnectionString %>" DefaultContainerName="CS3Entities"
EnableFlattening="False" EntitySetName="CustomersItems" Where="it.Authorised=false"
OrderBy="it.DateSet" >
</asp:EntityDataSource>