我有一些执行查询的代码.
int credenciadaId = 10;
var nome = from c in db.SanCredenciadas
where c.CredenciadaId == credenciadaId
select c.Name;
Run Code Online (Sandbox Code Playgroud)
我的问题分为两部分.
我希望查询只返回Name一个string.如何更改查询nome以使以下代码有效?
string name = nome;
Run Code Online (Sandbox Code Playgroud)
另外,我如何编写改进的查询,以便它使用lambda表达式和方法语法而不是当前的查询语法?
我不知道该怎么称呼这篇文章,但这是我的问题:
我有两个表:Online_Module&Offline_Module这两个表用于我的程序,以确定学习模块是否必须在线或在现场.
现在我也有一张叫做的桌子Academy.一个Academy由许多模块组成.为此,我想创建以下子表:Academy_has_Module
这就是问题所在.因为Online_Module并且Offline_Module不在同一个表中,我的其中一个值Academy_has_Module将永远存在null
以下是一些显示这些表的构建的图片:

如您所见,其中一个值将始终如一null.我想知道,在这种情况下最佳做法是什么?
编辑它的价值,承认可能不是那么多.我做了一点测试来扩展这个问题.
我写了两个函数来枚举FizzBuzz"系列".
private static IEnumerable<string> SimpleFizzBuzz(
int start = 0,
int end = int.MaxValue)
{
return Enumerable.Range(start, end).Select(i =>
i % 15 == 0 ? "fizzbuzz" :
i % 3 == 0 ? "fizz" :
i % 5 == 0 ? "buzz" :
i.ToString(CultureInfo.InvariantCulture));
}
Run Code Online (Sandbox Code Playgroud)
和,
private static IEnumerable<string> OptimizedFizzBuzz(
int start = 0,
int end = int.MaxValue)
{
const int fizz = 3;
const int buzz = 5;
const string fizzString = "fizz";
const string buzzString = "buzz"; …Run Code Online (Sandbox Code Playgroud) 我有一些文字
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
Run Code Online (Sandbox Code Playgroud)
我有一个正则表达式,它是从用户输入生成的.
@".*ip.*"
Run Code Online (Sandbox Code Playgroud)
这正如你所期望的那样匹配整行,所以我用字边界包装这个表达式.
@"\b.*ip.*\b"
Run Code Online (Sandbox Code Playgroud)
因为处理器是贪婪的,所以这仍然匹配整个文本.所以,我试过让重复变得懒惰.
@"\b.*?ip.*?\b"
Run Code Online (Sandbox Code Playgroud)
这是更好但匹配
Lorem ipsumdolor sit amet, consectetuer adipiscing如何扩展原始@".*ip.*"模式,使其懒惰地匹配整个单词和捕获?
ipsumadipiscing这个正则表达式测试器可能对回答问题很有用
我正在尝试做一个简单的数学picee,如果一个值在两个值之间,我会计算出来,如果是这样,那么它应该做一个简单的除法.然而,有时候除以的值是0.9,0.6等,并且总是返回0.
在这个例子中,
int m_LocationSqrMtr = 4339;
float m_DefaultPricing = Convert.ToSingle(DefaultPricing);
float m_manDays;
if (m_LocationCosts > 450 && m_LocationCosts < 700)
{
m_DefaultPricing = 700 / m_LocationSqrMtr;
}
Run Code Online (Sandbox Code Playgroud) 我有一个包含字符串的数组.我想将当前字符串与数组中的所有字符串进行比较,然后按字母顺序排列.我该怎么做呢?
澄清:字符串不按任何顺序排列.我想知道哪个索引具有下一个字母顺序的下一个字符串.例如,如果我有字符串"Bananas",我想从"Apple""Oranges"获得的下一个字符串"Bananas"将是"Oranges".
给出阵列
var fruit = new[] { "Apple", "Oranges", "Bananas" }
Run Code Online (Sandbox Code Playgroud)
我想要一个能通过这个测试的函数
Assert.AreEqual(1, NextGreatestIndex(fruit, 2))
Run Code Online (Sandbox Code Playgroud)
因为"Oranges"接下来是alphbetically "Bananas".
Parallel.ForEach继续运行,我的程序没有结束.我无法追踪第一次迭代后的位置.我的猜测是获得死锁并继续进行上下文切换.
private void ReadInputFile()
{
var collection = new ConcurrentBag<PropertyRecord>();
var lines = System.IO.File.ReadLines(InputFileName);
int i = 0;
int RecordsCount = lines.Count();
Parallel.ForEach(lines, line =>
{
if (string.IsNullOrWhiteSpace(line))
{
return;
}
var tokens = line.Split(',');
var postalCode = tokens[0];
var country = tokens.Length > 1 ? tokens[1] : "england";
SetLabelNotifyTwoText(
string.Format(
"Reading PostCode {0} out of {1}"
i,
lines.Length));
var tempRecord = GetAllAddesses(postalCode, country);
if (tempRecord != null)
{
foreach (PropertyRecord r in tempRecord)
{
collection.Add(r);
}
}
}); …Run Code Online (Sandbox Code Playgroud) 考虑三个参数:
@Y=2014
@M=11
@D=24
Run Code Online (Sandbox Code Playgroud)
我想在SQL Server中有一个函数,它获取三个数字并返回一个日期作为结果.
我有一个接口和两个类.
public interface IMyInterface { }
public class A : IMyInterface { }
public class B : IMyInterface { }
Run Code Online (Sandbox Code Playgroud)
我有一个通用的方法,
private List<T> GetList<T>(DataTable table)
where T : class, IMyInterface
{
...
}
Run Code Online (Sandbox Code Playgroud)
应该根据DataTable中的数据返回一个对象列表.所以,我在这个方法中创建了一个列表,我想在最后返回.我以为我可以做到以下几点,
private List<T> GetList<T>(DataTable table)
where T : class, IMyInterface
{
List<T> myList = new List<T>;
// Now I thought I could easily add Objects based on T because,
// both classes implement the interface
if (typeof(T) == typeof(B))
{
myList.Add(new B());
}
else
{
myList.Add(new A()); …Run Code Online (Sandbox Code Playgroud) 很难解释我用"普通"语言编写它的问题所以我只是发布我的代码(它会更容易理解):
我上课了File:
public class File
{
public string Url { get; set; }
public string Name { get; set; }
public string Date { get; set; }
public Bitmap Bitmap { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
所以我创建了一个列表files:
var files = new List<File>();
Run Code Online (Sandbox Code Playgroud)
而且,我已用数据填充它.
现在我有一个string(只有那个.)我想找到包含string在我的列表中的元素的索引.
就像是:
int index = files.IndexOf(new File
{
string.Empty,
myString,
string.Empty,
null
});
Run Code Online (Sandbox Code Playgroud)
任何的想法?