使用 LINQ to SQL 时,我可以将本地数据的值与数据库返回的值混合吗?
我正在使用 LINQ 创建一个 xml 文件,如下所示...
Public Sub CreateXml()
Dim db As New MDataContext
Dim Customers = <gallery columns="3" rows="3">
<%= From customer In db.Customers _
Select <customer>
<name><%= customer.CustName %></name>
<surname><%= customer.Surname %></surname>
</customer> %>
</gallery>
Customers.Save("d:\1.xml")
End Sub
我可以将本地值与从 LINQ 查询返回的值混合在一起吗... 像下面这样的东西吗?
Public Sub CreateXml(ByVal **Col** As String, ByVal **Row** As String)
Dim db As New MDataContext
Dim Customers = <gallery columns="& **Col** &" rows="& **Row** &">
<%= From customer In db.Customers _
Select <customer>
<name><%= customer.CustName %></name>
<surname><%= customer.Surname %></surname>
</customer> %>
</gallery>
Customers.Save("d:\1.xml")
Process.Start("d:\1.xml")
End Sub
I am creating an xml file with LINQ as follows...
Public Sub CreateXml()
Dim db As New MDataContext
Dim Customers = <gallery columns="3" rows="3">
<%= From customer In db.Customers _
Select <customer>
<name><%= customer.CustName %></name>
<surname><%= customer.Surname %></surname>
</customer> %>
</gallery>
Customers.Save("d:\1.xml")
End Sub
Could i mix local values with the ones returned from the LINQ query...
Something like the following?
Public Sub CreateXml(ByVal **Col** As String, ByVal **Row** As String)
Dim db As New MDataContext
Dim Customers = <gallery columns="& **Col** &" rows="& **Row** &">
<%= From customer In db.Customers _
Select <customer>
<name><%= customer.CustName %></name>
<surname><%= customer.Surname %></surname>
</customer> %>
</gallery>
Customers.Save("d:\1.xml")
Process.Start("d:\1.xml")
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够嵌入这两个变量的值,就像处理 customer.CustName 和 customer.Surname 一样,例如
严格来说,您应该进行适当的
ToString()
调用,例如<%= cols.ToString(CultureInfo.InvariantCulture) %>
。通过这种方式,您可以确保更改不会引入任何不必要的装箱,并且也独立于执行线程的区域性,尽管后者不太可能对 Integer 变量产生任何影响。You should be able to embed the values of the two variables just as you are doing with the customer.CustName and customer.Surname, e.g.
Strictly speaking, you should probably make an appropriate
ToString()
call, e.g.<%= cols.ToString(CultureInfo.InvariantCulture) %>
. This way you ensure that the change doesn't introduce any unnecessary boxing and is also independent of the culture of the executing thread, although the latter is not likely to have any affect with an Integer variable.