我想更改数据库表的列位置而不会丢失数据.
例如:
当前表格:
+----+------+-------+----------+
| id | name | email | password |
+----+------+-------+----------+
Run Code Online (Sandbox Code Playgroud)
至
+----+----------+------+-------+
| id | password | name | email |
+----+----------+------+-------+
Run Code Online (Sandbox Code Playgroud) - 在楠格哈尔省Surkhrod地区的一名路透社记者说,村民们说袭击事件发生后,阿富汗警方开始向当地政府大楼投掷石块后向人群开枪.
在上面的段落中,我想使用CSS来使第一行之后的所有行自动缩进一些空格,以便每行在第一行中的 - 之后保持正确.
HTML
<p> - A Reuters reporter in Surkhrod district in Nangarhar province, where
villagers said the raids took place, said Afghan police fired at the crowd
after some of them started throwing stones at local government buildings.</p>
Run Code Online (Sandbox Code Playgroud)
它类似于列表位置设置为外部的列表项,但我不想使用列表.
您能想到实现这种效果的最简单方法是什么?更少的额外HTML标记会更好.
非常感谢大家.
给定一个函数(string a, string b) F()
,你可以解构它返回的元组:
var (a, b) = F();
(string c, string d) = F();
Run Code Online (Sandbox Code Playgroud)
或者你可以分配它:
var (a, b) e = F();
(string a, string b) f = F();
var g = F(); // One of these things is not like the others.
Run Code Online (Sandbox Code Playgroud)
类解构器的行为与第一种情况类似.给定一个类C
有Deconstructor(out string a, out string b)
:
var c = new C();
var (h, i) = c;
(string j, string k) = c;
Run Code Online (Sandbox Code Playgroud)
但编译器不会使用解构函数将其隐式转换为元组:
// Cannot implicitly convert type …
Run Code Online (Sandbox Code Playgroud) 我不擅长Linq的表达,今天我遇到了一个奇怪的问题,如下面的内连接语句,
var orders = (from q in dao.CurrentDBContext.New_OrderForm
join d in dao.CurrentDBContext.New_OrderGoodsDetail on q.billNum equals d.billNum
select new
{
q.billNum,
q.orderSource,
q.sourceOddNum
d.PPT
}
Run Code Online (Sandbox Code Playgroud)
当我追踪linq语句时,我很困惑,Entity Framework
将linq语句转换为下面的sql语句
SELECT
[Extent1].[billNum] AS [billNum],
[Extent1].[orderSource] AS [orderSource],
[Extent1].[sourceOddNum] AS [sourceOddNum],
[Extent2].[PPT] AS [PPT]
FROM [dbo].[New_OrderForm] AS [Extent1]
INNER JOIN [dbo].[New_OrderGoodsDetail] AS [Extent2]
ON ([Extent1].[billNum] = [Extent2].[billNum]) OR
(([Extent1].[billNum] IS NULL) AND ([Extent2].[billNum] IS NULL))
Run Code Online (Sandbox Code Playgroud)
你知道为什么下面的SQL段会自动附加吗?
或(([Extent1].[billNum] IS NULL)AND([Extent2].[billNum] IS NULL) "
我不希望上面的内容自动附加,因为它确实降低了SQL性能.有什么建议?
我有RestSharp(类似于HttpClient)从Web Api方法调用和返回数据
我收到了这个错误 {"Cannot create an instance of an interface."}
我的代码看起来像这样:
public List<Interest> GetInterests()
{
var request = new RestRequest(apiPath + "GetInterests", Method.GET) { RequestFormat = DataFormat.Json };
var response = Client.Execute<List<Interest>>(request);
return response.Data;
}
Run Code Online (Sandbox Code Playgroud)
我的回答.内容如下所示.
现在问题似乎是DATA在响应对象的Content属性中作为JSON存在.我可以从那里手动反序列化它.但是之前是自动将其反序列化为Data属性,我不确定现在发生了什么.
如果我手动反序列化json,它可以工作 - 但为什么我需要这样做?
List<Interest> results = JsonConvert.DeserializeObject<List<Interest>>(response.Content);
Run Code Online (Sandbox Code Playgroud)
响应:
"StatusCode: OK, Content-Type: application/json; charset=utf-8, Content-Length: 5597)"
JSON代码返回
[
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":1,
"InterestName":"Nursing",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":2,
"InterestName":"Creating/Supporting Networks of Community Partners", …
Run Code Online (Sandbox Code Playgroud) 我有一个Collection List BossList.因为我使用嵌套的.Any()来确定条件.现在,我的实际项目中的性能非常慢.请考虑以下示例源代码.
void Main()
{
List<Boss> BossList = new List<Boss>()
{
new Boss()
{
ID = 101,
Name = "Harry",
Department = "Development",
Gender = "Male",
Role = "Manager",
Employees = new List<Person>() {
new Person() {
ID = 101,
SID = 102,
Name = "Peter",
Department = "Development",
Gender = "Male",
Role = "Assistant",
PayInfo = new List<PayrollInfo>()
{
new PayrollInfo() { Monthof2015 = 1, NetWorkingDays = 24, AbsentDays = 6 },
new PayrollInfo() { Monthof2015 = 2, …
Run Code Online (Sandbox Code Playgroud) 我创建了一个实现INotifyPropertyChanged
接口的基类.此类还包含一个通用函数,SetProperty
用于设置任何属性的值并在PropertyChanged
必要时引发事件.
Public Class BaseClass
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Protected Function SetProperty(Of T)(ByRef storage As T, value As T, <CallerMemberName> Optional ByVal propertyName As String = Nothing) As Boolean
If Object.Equals(storage, value) Then
Return False
End If
storage = value
Me.OnPropertyChanged(propertyName)
Return True
End Function
Protected Overridable Sub OnPropertyChanged(<CallerMemberName> Optional ByVal propertyName As String = Nothing)
If String.IsNullOrEmpty(propertyName) Then
Throw New ArgumentNullException(NameOf(propertyName))
End If
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub …
Run Code Online (Sandbox Code Playgroud) 以下内容仅创建 的一个实例MyTabView
。我通过在 MyTabView.xaml.cs 的构造函数中放置断点来确认这一点。该视图显示在一个选项卡中,无论我创建多少个选项卡,我只点击该构造函数一次。
<DataTemplate DataType="{x:Type vm:MyTabViewModel}" x:Shared="false">
<vw:MyTabView />
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
选项卡控制:
<TabControl
Grid.Row="1"
ItemsSource="{Binding Tabs}"
SelectedItem="{Binding SelectedTab}"
>
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding DisplayName}" />
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl>
Run Code Online (Sandbox Code Playgroud)
这会导致所有选项卡反映共享未绑定到视图模型的任何状态:如果您移动GridSplitter
,则所有其他选项卡中的情况都是相同的GridSplitter
,因此用户会觉得您移动了所有选项卡。这太荒谬了。
我不明白。有什么办法可以TabControl
同时使用多个相同类型的项目吗?
编辑:添加x:Shared="false"
到DataTemplate
.
更新:
所以我找到了一些修复方法,但我不太喜欢它们。我将考虑编写一个转换器来转换ObservableCollection<Object>
为ObservableCollection<TabItem>
- 有点像实时更新版本
coll.Select(vm => new TabItem() { Content = vm });
Run Code Online (Sandbox Code Playgroud)
...但我们会看看它是否喜欢TabItem
从 获取实例ItemsSource
。我的钱说不要赌它。但我们会看到。
更新2:花了一段时间才回到这个话题。交换选项卡项目集合的花招是有效的,但SelectedItem
存在问题。事实证明,还有另一种解决方案(如下)不会产生该问题,并且还避免了创建必须镜像源集合中的更改的“中间人”集合的复杂性和愚蠢性。
我有一个字符串数组,我已将其设置为ListView的项目源.ListView现在具有与数组具有元素相同的行数.但是我不知道将绑定设置为什么.我知道一个字典我设置'价值',它工作得很好.
string[] array = {"1","2","3"};
MyListView.ItemsSource = array;
Run Code Online (Sandbox Code Playgroud)
XAML
<ListView x:Name="MyListView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Value, StringFormat='The value : {0:N}'}" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Run Code Online (Sandbox Code Playgroud) 我有一个介于0到255之间的921600数字的数组.
我需要检查每个数字是否高于阈值.
是否可以同时检查阵列的前半部分和后半部分,以减少运行时间?
我的意思是,是否可以并行运行以下两个for循环?
for(int i = 0; i < 921600 / 2; i++)
{
if(arr[i] > 240) counter++;
}
for(int j = 921600 / 2; j < 921600; j++)
{
if(arr[j] > 240) counter++;
}
Run Code Online (Sandbox Code Playgroud)
先感谢您!
c# ×6
linq ×2
wpf ×2
xaml ×2
.net ×1
arrays ×1
byref ×1
c#-7.0 ×1
css ×1
datatemplate ×1
html ×1
indentation ×1
join ×1
json ×1
mysql ×1
restsharp ×1
sql ×1
tabcontrol ×1
text-indent ×1
valuetuple ×1
vb.net ×1
xamarin ×1
xamarin.ios ×1