SQL Server中的数据库和架构之间有什么区别?两者都是表和数据的容器.
如果删除了Schema,那么该架构中包含的所有表是否也会自动删除,或者在删除数据库时是否删除它们?
我有一个VB投影并使用在线转换工具将其转换为C#.现在的问题是xaml
和xaml.cs
文件没有相互连接,也就是说它们不能识别它们的依赖关系(图中的红色区域).实际上它应该看起来像Window1文件(图像中的绿色区域.)我怎样才能实现这一点.
我正在尝试WPF,所以可能是一个外行问题.
我试图获取列表中的第一个值和最后一个值.查询经营者First()
的支持,但Last()
并LastOrDefault()
给出错误.我是否Last()
以错误的方式使用操作员?
var purchaseBills = db.PurchaseBills.OrderBy(p => p.BillID);
if (purchaseBills.Count() >0)
{
var firstBill= purchaseBills.First(); //This is supported
//Attempt 1
var lastBill = purchaseBills.Last(); // Not supported
//Attempt 2
var lastBill = purchaseBills.LastOrDefault(); //Not supported
//Attempt 3
var lastBill = purchaseBills.Reverse().First(); //Not supported
textBoxPurchaseBillFrom.Text = firstBill.BillNo.ToString();
textBoxPurchaseBillTo.Text = lastBill.BillNo.ToString();
}
Run Code Online (Sandbox Code Playgroud)
更新: - 错误 -
尝试1:不支持查询运算符"Last".
尝试2:不支持查询运算符"LastOrDefault".
尝试3:不支持查询运算符"反向".
我ViewModel1
和View1相关联.我ViewModel2
使用IWindowManager
object 从(另一个viewmodel)启动对话框窗口.ViewModel2
类中的代码:
windowManager.ShowDialog(new ViewModel());
Run Code Online (Sandbox Code Playgroud)
所以,我有Viewop窗口和View1用户控件.
我的答案是下一个 - 我可以使用红色关闭按钮关闭该对话框窗口,但是如何使用我的特定按钮(包含在View1
用户控件中)关闭它,类似"取消"按钮和关闭命令(Command={Binding CancelCommand}
),CancelCommand
当然包含在ViewModel1
课堂上.
我对LINQ to SQL很新,所以请原谅我,如果它是一个外行问题.
我在许多地方看到我们"select new"
在查询中使用关键字.例如
var orders = from o in db.Orders select new {
o.OrderID,
o.CustomerID,
o.EmployeeID,
o.ShippedDate
}
Run Code Online (Sandbox Code Playgroud)
为什么我们不删除select new而只是使用 "select o"
var orders = from o in db.Orders select o;
Run Code Online (Sandbox Code Playgroud)
我可以区分的是速度方面的性能差异,即第二次查询将比第一次查询花费更多的时间执行.
它们之间是否存在其他"差异"或"更好用"的概念?
我指的是一篇专注于加速LINQ to SQL Queries的文章.它提到的技术之一是"使用编译查询"并解释了如何使用它.
我想看看编译查询的性能改进,因此我尝试了作者提供的相同示例.我使用Northwind Db作为datacontext.我尝试了正常执行和编译查询执行,并在LINQ PAD上检查它们.
首先,我尝试不使用CompileQuery 执行查询.花了2.065秒.
var oo = from o in Orders
where o.OrderDetails.Any (p => p.UnitPrice > 100)
select o;
oo.Dump ("Order items with unit price more than $100");
var oo1 = from o in Orders
where o.OrderDetails.Any (p => p.UnitPrice > 10)
select o;
oo1.Dump ("Order items with unit price more than $10");
Run Code Online (Sandbox Code Playgroud)
其次,查询与使用CompileQuery.花了2.100秒.
var oo = CompiledQuery.Compile ((TypedDataContext dc, decimal unitPrice) =>
from o in Orders
where …
Run Code Online (Sandbox Code Playgroud) 在C#Web应用程序中使用NLog时,使用存储过程而不是SQL INSERT语句时遇到了一些问题.连接字符串"Logger"在Web.config中正确配置,并在用SQL语句替换commandText时正常工作.我希望得到正确方向的暗示.在此示例中,存储过程位于"Logs"模式下,称为"LogError".
<targets>
<target xsi:type="Database"
name="dberrorlog"
connectionStringName="Logger"
keepConnection="true"
commandText="[Logs].[LogError]" >
<parameter name="@ProgName" layout="MyAppName"/>
<parameter name="@CompName" layout="${machinename}"/>
<parameter name="@LogLevel" layout="${level}"/>
<parameter name="@UserName" layout="${identity}"/>
<parameter name="@Error" layout="${exception:format=Message}"/>
<parameter name="@SourceObj" layout="${exception:format=Method}"/>
<parameter name="@StackTrace" layout="${exception:format=StackTrace}"/>
</target>
</targets>
<rules>
<logger name="*" minlevel="Error" writeTo="dberrorlog" />
</rules>
Run Code Online (Sandbox Code Playgroud) 我编写了以下代码来配置MainForm加载时的串口.在第一次运行时,它会IOException
在端口打开时给出,说明参数不正确.但是,当我重新启动应用程序时,它工作正常.只有在启动计算机后第一次运行应用程序时才会出现异常,然后它才能正常工作,直到下次重新启动计算机.
private void Main_Load(object sender, EventArgs e)
{
this.serialPort1.PortName = "COM3";
this.serialPort1.BaudRate = 9600;
this.serialPort1.DataBits = 8;
this.serialPort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort1_DataReceived);
this.serialPort1.Open(); //Exception comes here
this.serialPort1.WriteLine("AT#cid=1" + System.Environment.NewLine);
}
Run Code Online (Sandbox Code Playgroud)
执行细节:
System.IO.IOException未被用户代码处理
Message ="参数不正确.\ r \n"Source ="System"
堆栈跟踪:在System.IO.Ports.InternalResources.WinIOError(的Int32的errorCode,字符串str)在System.IO.Ports.InternalResources.WinIOError()在System.IO.Ports.SerialStream.set_RtsEnable(布尔值)System.IO. Ports.SerialStream..ctor(字符串PORTNAME,的Int32波特率,奇偶校验位,数据位的Int32,停止位停止位,的Int32 readTimeout,的Int32 writeTimeout,握手握手,布尔dtrEnable,布尔rtsEnable,布尔discardNull,字节parityReplace)在System.IO.Ports. SerialPort.Open()在JKamdar.Main.Main_Load(对象发件人,EventArgs e)在d:\项目\ JKamdar\JKamdar\Main.cs:线264处系统System.Windows.Forms.Form.OnLoad(EventArgs的) .Windows.Forms.Form.OnCreateControl()在System.Windows.Forms.Control.CreateControl(布尔fIgnoreVisible)在System.Windows.Forms.Control.CreateControl()在System.Windows.Forms.Control.WmShowWindow(邮件&m)在System.Windows.Forms.Control.WndProc在System.Windows.Forms.ScrollableControl.WndProc在System.Windows(邮件&m)(邮件&m).Forms.ContainerControl.WndProc(消息&m)上System.Windows.Forms.Form.WmShowWindow在System.Windows.Forms.Control.ControlNativeWindow.OnMessage在System.Windows.Forms.Form.WndProc(邮件&m)(邮件&m) (消息&m)上在System.Windows.Forms.NativeWindow.Callback System.Windows.Forms.Control.ControlNativeWindow.WndProc(邮件&m)(IntPtr的的HWND,MSG的Int32,IntPtr的WPARAM,IntPtr的LPARAM)的InnerException:
当有人打电话时,我使用以下方法来检测来电显示.
在表单加载时,我设置以下代码:
this.serialPort1.PortName = "COM3";
this.serialPort1.BaudRate = 9600;
this.serialPort1.DataBits = 8;
this.serialPort1.RtsEnable = true;
this.serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
this.serialPort1.Open();
this.serialPort1.WriteLine("AT#cid=1" + System.Environment.NewLine);
void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
richTextBox1.Text += this.serialPort1.ReadLine();
//richTextBox1.Text += this.serialPort1.ReadExisting();
//richTextBox1.Text += this.serialPort1.ReadByte().ToString();
}
Run Code Online (Sandbox Code Playgroud)
命令
this.serialPort1.WriteLine("AT#cid=1" + System.Environment.NewLine);
Run Code Online (Sandbox Code Playgroud)
给了我输出
OK
Run Code Online (Sandbox Code Playgroud)
这确保了调制解调器支持调制解调器ID并且正在工作.
我在我们国家(印度)试过一些私人电话线,它给出了预期的输出如下.
RING //On 1st Ring
DATE = xxxxx //On 2nd Ring
TIME = xxxx
NMBR = xxxxxxxxx
RING //On 3rd Ring
RING //On 4th Ring
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用政府电话(印度的BSNL公司)时,它没有提供DATE,TIME和NMBR部分.它给出了以下输出.
RING //On 1st Ring
RING //On 3rd Ring
RING …
Run Code Online (Sandbox Code Playgroud) c# ×8
.net ×6
linq-to-sql ×3
linq ×2
serial-port ×2
wpf ×2
database ×1
dialog ×1
nlog ×1
performance ×1
phone-call ×1
sql-server ×1
vb.net ×1
window ×1
xaml ×1