有哪些替代方法可以实现以下查询:
select *
from table
where isExternal = @type = 2 ? 1 : 0
Run Code Online (Sandbox Code Playgroud) 我有一个简单的课程:
private class Category
{
public int Id { get; set; }
public string Value { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
还有这种类型的对象列表:
List<Category> Categories;
Run Code Online (Sandbox Code Playgroud)
我需要获取类别列表中的ID列表.有没有比使用for循环更简单的方法:
List<int> list = new List<int>();
for (int i = 0; i < Categories.Count; i++)
{
list.Add(Categories[i].Id);
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
如何从DataRow单元格中解析int值?
Int32.Parse(item["QuestionId"].ToString());
Run Code Online (Sandbox Code Playgroud)
这段代码有效,但看起来太冗长了.还可以处理DBNull值吗?
我正在为Universal App(Windows和Windows Phone)设计TextBox控件.我发现选择颜色可以通过'SelectionHighlightColor'属性设置(图片上的蓝色).但不知何故,选择括号似乎保持系统强调颜色(在我的情况下为绿色):

如何设置括号颜色或重新定义强调色?
更新:
我试图重新定义许多主题画笔和颜色,例如:
((SolidColorBrush)Resources["PhoneAccentBrush"]).Color = Color.FromArgb(0xFF, 0x00, 0x00, 0xFF);
Run Code Online (Sandbox Code Playgroud)
和
(Resources["PhoneAccentColor"]) = Color.FromArgb(0xFF, 0x00, 0xFF, 0xFF);
Run Code Online (Sandbox Code Playgroud)
这确实重新定义了重音,但没有任何东西对括号产生影响.他们仍然是绿色的......
我希望本地化我在App.xaml中制作的App Bar,但是当我尝试绑定条形项目的文本时,它说文本不能为空,我尝试了本地化应用程序栏的其他示例,但它们都没有用于app栏,可以在所有页面上使用..
当它声明为:时,我可以在PivotItem上设置Margin属性:
<phone:Pivot Margin="50,0,50,0">
<phone:PivotItem Margin="0">
<TextBlock>Text</TextBlock>
</phone:PivotItem>
</phone:Pivot>
Run Code Online (Sandbox Code Playgroud)
但是当我使用绑定时如何设置边距:
<phone:Pivot Margin="50,0,50,0">
<phone:Pivot.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Body}"/>
</DataTemplate>
</phone:Pivot.ItemTemplate>
</phone:Pivot>
Run Code Online (Sandbox Code Playgroud)
如何在DataTemplate上设置保证金?
我在mvc 4 app中有一个控制器动作:
public ActionResult Index()
{
GetStartedModel gsModel = new GetStartedModel();
return View(gsModel);
}
Run Code Online (Sandbox Code Playgroud)
和ViewModel:
public class GetStartedModel
{
public IEnumerable<SelectListItem> listA { get; set; }
public IEnumerable<SelectListItem> listB { get; set; }
public GetStartedModel()
{
TestDataWebServiceHelper service = new TestDataWebServiceHelper();
this.GetData(service);
}
private async void SetData(TestDataWebServiceHelper service)
{
listA = await this.SetListA(service);
listB = await this.SetListB(service);
}
private async Task<IEnumerable<SelectListItem>> SetListA(TestDataWebServiceHelper service)
{
List<String> rawList = new List<String>();
rawList = await service.GetValuesAsync("json");
return rawList.Select(x => new SelectListItem { …Run Code Online (Sandbox Code Playgroud) 我的需要是注入 HttpClient 并立即可供使用。但需要注意的是 HttpClient 需要设置Authorization标头,为此我需要再进行一次调用以获取令牌。我设法在启动的 RegisterServices 中完成所有这些配置,但我怀疑这是否是一个好主意。
services.AddHttpClient("OidcClient", (isp, client) =>
{
var options = isp.GetRequiredService<IOptions<MyConfig>>().Value;
client.BaseAddress = new Uri(options.OidcUrl);
});
services.AddHttpClient("MyClient", (isp, client) =>
{
var options = isp.GetRequiredService<IOptions<MyConfig>>().Value;
var oidcClient = isp.GetRequiredService<IHttpClientFactory>().CreateClient("OidcClient");
var data = new Dictionary<string, string>
{
{"client_id", options.ClientId},
{"client_secret", options.ClientSecret}
};
var request = new HttpRequestMessage(HttpMethod.Post, "/connect/token") { Content = new FormUrlEncodedContent(data) };
var response = oidcClient.SendAsync(request).Result;
var token = response.Content.ReadFromJsonAsync<TokenResponse>().Result;
client.BaseAddress = new Uri(options.Url);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Token);
});
Run Code Online (Sandbox Code Playgroud)
然后它被正确地注入到我的代码中,我可以使用带有授权标头的客户端。
所以,我的担忧是: …
c# ×6
xaml ×3
.net-5 ×1
.net-core ×1
asp.net-mvc ×1
async-await ×1
linq ×1
sql-server ×1
t-sql ×1
windows-8.1 ×1