我有一张表,记录看起来像这样
varchar(255) Name
varchar(255) Text
varchar(255) Value
Run Code Online (Sandbox Code Playgroud)
Name是DDL名称,Text是显示的内容,Value是在选择时返回的.每个名称都有一到二十个选项.如果不像游标那样迭代每个选项,是否有任何方法可以使用Linq和C#拉出一个对象列表,每个唯一的DDL名称一个?
数据样本:
Beds '4 (10)' 4
Beds '5 (1)' 5
Beds '7 (1)' 7
Baths 'NA (13)' NULL
Baths '0 (1)' 0
Baths '1 (13)' 1
Run Code Online (Sandbox Code Playgroud)
我正在考虑做一个外部选择以获取唯一的名称,然后使用内部选择来获取它的选项列表,然后将该集合作为一组列表的列表返回.
我有以下C#代码,它们应匹配数量/ $ price字符串,如"4/$ 3.99".它整天都在工作,直到我们对Firefox浏览器返回的字符串使用它.77.77变为77(降低.77美分).
var matches = Regex.Match(_priceText,
@"^\s?((?<qty>\d+)\s?/)?\s?[$]?\s?(?<price>[0-9]?\.?[0-9]?[0-9]?)");
if( matches.Success)
{
if (!Decimal.TryParse(matches.Groups["price"].Value, out this._price))
this._price = 0.0m;
if (!Int32.TryParse(matches.Groups["qty"].Value, out this._qty))
this._qty = (this._price > 0 ? 1 : 0);
else
if (this._price > 0 && this._qty == 0)
this._qty = 1;
}
Run Code Online (Sandbox Code Playgroud)
知道为什么这段时间不会来自Firefox字符串,但C#字符串匹配?我们使用的Firefox没有任何特殊之处.这是Firefox网站上简单的简1252代码页下载.计算机的本地设置是不变的北美等.我们有两台不同的计算机显示相同的效果.它是Firefox 3.6.4,没什么花哨或测试版.
我是知识库的新手.我刚刚阅读了有关实现谓词和工作单元(Fowler)的内容.我见过存储库接口,如下所示:
public interface IRepository<ET> {
ET Add( ET entity);
ET Remove( int id);
ET Get( int id);
IList<ET> Get(Expression<Func<T, bool>> predicate);
}
Run Code Online (Sandbox Code Playgroud)
当然,工作单元会将数据上下文(Microsoft粉丝)注入新的存储库,其中工作单元将具有.Save()方法,在所有数据上下文中调用Save.
没有Edit方法,所以我假设您可以修改从存储库中弹出的任何实体,然后在工作单元上调用保存更改.
它是否正确?漏?我错过了什么?OrderBy的方法是否不必存在于存储库中?Paging(.Skip().Take())应该以某种方式在谓词中实现吗?
链接到示例代码将是非常棒的,尤其是如何在存储库中实现谓词.
LinqPad中的这段代码在Regex中输出一串数字:
void Main()
{
string a = "1, 2, 3, 4, 5, 6, 7";
var myList = Regex.Match(a, @"^\s*((\d+)\s*,?\s*)+\s*$")
.Groups[2].Captures.ToList();
myList.Dump();
}
public static class EM
{
public static List<string> ToList( this CaptureCollection value)
{
var result = new List<string>();
foreach( var item in value)
{
result.Add( ((Capture) item).Value );
}
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
它的工作原理,但我主要关注的是只使用正则表达式将数字放在字符串数组中.是否有一些简短而甜蜜的东西可以完成同样的事情?
编辑:
我正在使用正则表达式,因为我需要解析这样的事情:
string a = "deptid = 1, 2, 3, 4, 5, 6, 7";
var myList = Regex.Match(a,
@"^\s*(?<field>[A-Za-z0-9]+)\s*(?<op>==?)\s*((\d+)\s*,?\s*)+\s*$")
.Groups[2].Captures.ToList();
Run Code Online (Sandbox Code Playgroud) 我有一个带有几个IEnumerable集合的对象:
public class Product
{
public int id {get;set;}
public string name {get;set;}
IEnumerable<CrossSell> CrossSells {get;set;}
IEnumerable<UpSell> UpSells {get;set;}
IEnumerable<PricePromos> PricePromos {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
我需要创建一个null对象(所有属性都是空的但不是null).显然,我不能只创建一个Enumerable项目.
除了创建一个全新的课程,我怎么能这样做?