我需要在SQL Server Integration Services的表达式生成器中转义引号.我无法通过双引号或三引号来逃避它.
我现在可能完全偏离轨道,所以我会在这里问这个,所以有人可以帮助我.
我想要做的是将存储在applicationSettings区域的web.config中的值插入到我的aspx标记中.具体来说,我想从配置中恢复URL.这是我使用的configSection设置
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=123456">
<section name="MyApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=12345" requirePermission="false" />
</configSections>
Run Code Online (Sandbox Code Playgroud)
稍后在该文件中的实际设置如下:
<applicationSettings>
<MyApp.Properties.Settings>
<setting name="ImagesUrl" serializeAs="String">
<value>http://resources/images/</value>
</setting>
Run Code Online (Sandbox Code Playgroud)
现在我想在标记中引用上面的值,如下所示:
<asp:Image ID="Image1" runat="server" ImageUrl="<%$AppSettings:ImagesUrl%>/Image1.jpg
Run Code Online (Sandbox Code Playgroud)
我知道有一个表达式<%$ AppSettings:ImagesUrl%>,但我没有使用web.config的appsettings部分,而是使用configSection.
编辑:我相信我只能用ExpressionBuilder来做,因为我必须将字符串与单个图像名称连接起来.我改变了上面的例子来反映这一点.
我喜欢下面的Bert Smith Code Solution来访问配置部分,只需要将它放在表达式构建器中.我坚持要从我调用配置管理器的地方覆盖GetCodeExpression方法,但我不明白如何构建表达式参数.
public class SettingsExpressionBuilder: ExpressionBuilder
{
public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
{
return ??
}
Run Code Online (Sandbox Code Playgroud)
编辑
结果如下所示,适用于各种文件,而不仅仅是图像:
<asp:ScriptReference Path='<%$Code:GetAppSetting("ResourcesUrl","JS/jquery/jquery.jqplot.js")%>'
Run Code Online (Sandbox Code Playgroud)
我只是使用Microsoft的示例从表达式构建器返回任何类型的代码:
返回新的CodeSnippetExpression(entry.Expression);
GetAppSetting是我的自定义Page类中的一种方法.
我看到了一个使用Expression Builders的例子,并在这里创建自己的Custom Expression Builder类:
http://aspnet.4guysfromrolla.com/articles/022509-1.aspx
但是,我没有看到使用这种方法的价值.它似乎没有比在后面的代码中以编程方式设置值更容易.
据我所知,你唯一可以做的就是设置属性.也许它们可以用于设置某些控件的默认值?
任何人都可以了解这个ASP.NET功能变得强大的地方吗?
我想使用ASP.NET的ExpressionBuilder语法从AppSetting动态检索静态内容的域.
我使用以下语法,这不起作用:
<img src="<%$Appsettings:STATIC_CONTENT_DOMAIN %>/img/logo.jpg" alt="logo" width="176" height="159" />
Run Code Online (Sandbox Code Playgroud)
仅供参考,所需的HTML输出是:
<img src="http://static.myserver.com/img/logo.jpg" alt="logo" width="176" height="159" />
Run Code Online (Sandbox Code Playgroud)
请注意,我不能使用<%=%>语法,因为我的ASPX页面需要是CompilationMode ="never".(我使用ExpressionBuilder语法的原因是它在无编译页面中工作)
有关如何做到这一点的任何想法?
我有一个列表,我必须过滤子属性.过滤器运算符是动态的,我正在使用谓词构建器来组合多个过滤器/ lambdas.
为简单起见,我们假设我有两个这样的类:
public class FirstClass
{
public int Id { get; set; }
public ICollection<SecondClass> MyList { get; set; }
}
public class SecondClass
{
public int ReferenceId { get; set; }
public int Value { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的过滤器使用引用id,运算符类型和值,这样伪代码就像这样:
"list of FirstClass".Where(param1 =>
param1.MyList.Single(param2 =>
param2.ReferenceId == "reference id").Value "operatorType" "value")
Run Code Online (Sandbox Code Playgroud)
实际的过滤器类似于123 eq 456,其中引用标识为123,operatorType为"eq",值为456.
如果运算符只是相等,那么以下工作就可以了:
Expression<Func<FirstClass, bool>> lambda =
param1 => param1.MyList.Single(param2 => param2.ReferenceId == id).Value == value;
Run Code Online (Sandbox Code Playgroud)
此外,仅FirstClass使用动态表达式进行过滤,就像魅力一样,例如过滤Id(我的ExpressionTypeDictionary是用于ExpressionType根据提供的选择的字典operatorType): …
使用 SQL Server Integration Services 时,我喜欢保持灵活性,因此我将所有硬编码名称保留在变量中。这意味着要大量使用表达式生成器,但问题是实际表达式的字体大小太小,尤其是在编写代码时。
我发现自己经常在 SSIS 和 Notepad++ 之间复制和粘贴,一定有一种方法可以调整字体大小,但我一直找不到它。
我正在尝试构建一个 LINQ 表达式,以从 int 属性中过滤值:
protected IQueryable<T> Some(IEnumerable<int> ids)
{
var parameter = Expression.Parameter(typeof(T), "x");
// "Col_id" (int property)
var property = Expression.Property(parameter, "Col_id");
MethodInfo method = typeof(Enumerable).
GetMethods().
Where(x => x.Name == "Contains").
Single(x => x.GetParameters().Length == 2).
MakeGenericMethod(typeof(T));
// ids = { 2, 4, 8 } etc...
var value = Expression.Constant(ids, typeof(IEnumerable<int>));
var containsMethod = Expression.Call(method, property, value); // exception
var aDelegate = Expression.Lambda<Func<T, bool>>(containsMethod, parameter);
table = myDataContext.GetTable<T>();
return table.AsQueryable().Where(aDelegate);
}
Run Code Online (Sandbox Code Playgroud)
我试图得到类似的东西:(x => ids.Contains(x.Col_id)),但抛出异常:
'System.Int32' …
我无法理解为什么我的Update Query只获取最后一行中的值并将其放在同一列中的所有其他值中.
这是图片:
所以,我需要计算百分比(PBrojProdPoTip),给定BrojProdPoTip和VkBrojProdPoTip这是总和.
PBrojProdPoTip = BrojProdPoTip * 100 / VkBrojProdPoTip
Run Code Online (Sandbox Code Playgroud)
如果您尝试最后一个值,则18248中的244个给出01.34%
P = 244 * 100 / 18248 = 1.34%
Run Code Online (Sandbox Code Playgroud)
我做错了什么?为什么只需要一个值?
我的代码可以被认为是重复的:
private IEnumerable<decimal?> GetWidth(IEnumerable<Rectangle> rectangles) =>
rectangles.Where(s => s.Width != null)
.Select(s => s.Width);
private IEnumerable<decimal?> GetHeight(IEnumerable<Rectangle> rectangles) =>
rectangles.Where(s => s.Height != null)
.Select(s => s.Height);
private IEnumerable<decimal?> GetDiameter(IEnumerable<Rectangle> rectangles) =>
rectangles.Where(s => s.Diameter != null)
.Select(s => s.Diameter);
private IEnumerable<decimal?> GetWeight(IEnumerable<Rectangle> rectangles) =>
rectangles.Where(s => s.Weight != null)
.Select(s => s.Weight);
Run Code Online (Sandbox Code Playgroud)
这些方法之间的唯一区别只是字段名称,例如Width, Height, Diameter, Weight. 是否可以用字符串属性名称替换这些名称并仅创建一种方法而不使用任何第三方库?
我添加了一个函数来获取Active Directory用户登录,对于使用 VBA 的 Access DB,但我不确定为什么我看不到表达式生成器中列出的函数
我像这个问题一样定义了函数,但我在表达式生成器中看不到该函数。我计划使用这个函数在我的表单上填充一个不可见的txtBox并将其记录到数据库中。
Public Function GetUser(Optional whatpart = "username")
Dim returnthis As String
If whatpart = "username" Then GetUser = Environ("USERNAME"): Exit Function
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.USERNAME)
Select Case whatpart
Case "fullname": returnthis = objUser.FullName
Case "firstname", "givenname": returnthis = objUser.givenName
Case "lastname": returnthis = objUser.LastName
Case Else: returnthis = Environ("USERNAME")
End Select
GetUser = returnthis
End Function
Run Code Online (Sandbox Code Playgroud)
c# ×4
asp.net ×3
linq ×3
ms-access ×2
ssis ×2
vba ×2
appsettings ×1
contains ×1
font-size ×1
fonts ×1
ienumerable ×1
markup ×1
sql-server ×1
vb.net ×1
web-config ×1