我有一个搜索表单,允许用户以几种不同的方式搜索几个不同的字段.这是我的代码示例.
var claims = from c in db.Claims select c;
switch (ddlSearchField.Text)
{
case "StartsWith":
claims = claims.Where(c => c.companyFileID.StartsWith(txtSearchBox.Text));
break;
case "Equals":
claims = claims.Where(c => c.companyFileID == txtSearchBox.Text);
break;
case "Contains":
claims = claims.Where(c => c.companyFileID.Contains(txtSearchBox.Text));
break;
}
Run Code Online (Sandbox Code Playgroud)
我有大约十个不同的字段,用户可以搜索,所以我的外部开关语句非常大.必须有一种更优雅的方式来实现这一目标.
我想使用LINQ将输入XML转换为输出XML,方法是在"Summary"字段上执行GROUPBY并将Balance字段向上扩展.
输入XML:
<Root>
<Account>
<Summary>Checking</Summary>
<Comprehensive>Interest Checking Account</Comprehensive>
<Currency>Dollar</Currency>
<Balance>10000000.000000</Balance>
</Account>
<Account>
<Summary>Savings</Summary>
<Comprehensive>Market Account</Comprehensive>
<Currency>Dollar</Currency>
<Balance>20000000.000000</Balance>
</Account>
<Account>
<Summary>Checking</Summary>
<Comprehensive>Interest Checking Account</Comprehensive>
<Currency>Dollar</Currency>
<Balance>50000000.000000</Balance>
</Account>
</Root>
Run Code Online (Sandbox Code Playgroud)
输出XML:
<Root>
<Account>
<Summary>Checking</Summary>
<Comprehensive>Interest Checking Account</Comprehensive>
<Currency>Dollar</Currency>
<Balance>60000000.000000</Balance>
</Account>
<Account>
<Summary>Savings</Summary>
<Comprehensive>Market Account</Comprehensive>
<Currency>Dollar</Currency>
<Balance>20000000.000000</Balance>
</Account>
</Root>
Run Code Online (Sandbox Code Playgroud)
我试过这个,但无法获取节点/元素:
XElement groupData = new XElement("Root",
chartData.Elements().GroupBy(x => x.Element("Summary").Value).
Select(g => new XElement("Account", g.Key, g.Elements("Comprehensive"),
g.Elements("Currency"),
g.Sum(
s =>
(decimal)
s.Element("Balance")))));
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.提前致谢.
如何实现SquishIt在View Pages中捆绑Css/Js并在Master页面中渲染它?我以为我可以在Render部分上方使用ContentPlaceHolder,但似乎有一些奇怪的行为,它有时会添加3个文件(视图页面中有1个文件,母版页中有2个文件)但是其他时候会忽略从View中添加的文件页.
的Index.aspx
<asp:Content ContentPlaceHolderID="CssFiles" runat="server">
<% CssHelper.Add("home.css"); %>
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
的Site.Master
<asp:ContentPlaceHolder ID="CssFiles" runat="server" />
<% CssHelper.Add("reset.css"); %>
<% CssHelper.Add("master.css"); %>
<%=CssHelper.Render() %>
Run Code Online (Sandbox Code Playgroud)
我目前的解决方案是围绕SquishIt的静态Bundle类的静态包装器,它将BundleBuilder保存在HttpContext.Current.Items中.
我很好奇这是否已成功完成以及如何做到这一点.
我有一个名为User的对象,其中包含Username,Age,Password email等属性.
我在ado.net代码中初始化此对象,如:
private User LoadUser(SqlDataReader reader)
{
User user = new User();
user.ID = (int)reader["userID"];
// etc
}
Run Code Online (Sandbox Code Playgroud)
现在说我创建一个继承自User的新对象,如:
public class UserProfile : User
{
public string Url {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
现在我需要创建一个加载userprofile的方法,所以目前我在做:
public UserProfile LoadUserProfile(SqlDataReader reader)
{
UserProfile profile = new UserProfile();
profile.ID = (int)reader["userID"];
// etc. copying the same code from LoadUser(..)
profile.Url = (string) reader["url"];
}
Run Code Online (Sandbox Code Playgroud)
是否有更多的OOP方法,所以我不必从LoadUser()在LoadUserProfile()镜像我的代码?
我希望我能做到这一点:
UserProfile profile = new UserProfile();
profile = LoadUser(reader);
// and then init my profile related properties
Run Code Online (Sandbox Code Playgroud)
可以这样做吗?
asp.net ×2
c# ×1
css ×1
group-by ×1
javascript ×1
linq ×1
linq-to-sql ×1
linq-to-xml ×1
oop ×1
squishit ×1