Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 实体数据源连接字符串作为变量_C#_Asp.net_Entity Framework - Fatal编程技术网

C# 实体数据源连接字符串作为变量

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

如何从codebehind页面中的变量集设置实体数据源连接字符串

e、 g.在代码背后类似这样的东西

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>