我需要一个Postgres函数来返回一个带有自定义内容的虚拟表(就像在Oracle中一样).该表将有3列和未知行数.
我在互联网上找不到正确的语法.
想象一下:
CREATE OR REPLACE FUNCTION "public"."storeopeninghours_tostring" (numeric)
RETURNS setof record AS
DECLARE
open_id ALIAS FOR $1;
returnrecords setof record;
BEGIN
insert into returnrecords('1', '2', '3');
insert into returnrecords('3', '4', '5');
insert into returnrecords('3', '4', '5');
RETURN returnrecords;
END;
Run Code Online (Sandbox Code Playgroud)
这怎么写的正确?
想象一下这样的函数:
private static ConcurrentList<object> list = new ConcurrentList<object>();
public void Add(object x)
{
Task.Factory.StartNew(() =>
{
list.Add(x);
}
}
Run Code Online (Sandbox Code Playgroud)
我不在乎什么时候确实将fentry添加到列表中,但我需要将它添加到最后(显然;))
我没有看到一种方法来正确地单元测试这样的东西而不返回任何回调处理程序或某事.因此,添加程序不需要的逻辑
你会怎么做?
对于我当前的项目,有必要生成动态CSS ...
所以,我有一个局部视图作为CSS传递者......控制器代码如下所示:
[OutputCache(CacheProfile = "DetailsCSS")]
public ActionResult DetailsCSS(string version, string id)
{
// Do something with the version and id here.... bla bla
Response.ContentType = "text/css";
return PartialView("_css");
}
Run Code Online (Sandbox Code Playgroud)
输出缓存配置文件如下所示:
<add name="DetailsCSS" duration="360" varyByParam="*" location="Server" varyByContentEncoding="none" varyByHeader="none" />
Run Code Online (Sandbox Code Playgroud)
问题是:当我使用OutputCache行([OutputCache(CacheProfile ="DetailsCSS")])时,响应的内容类型为"text/html",而不是"text/css"...当我删除它时,它按预期工作......
所以,对我来说,似乎OutputCache没有保存我的"ContentType"设置......有什么方法可以解决这个问题吗?
谢谢
我在网上搜索了一些结果,但它们似乎都不适合这项任务.我正在寻找.NET的可能性,但也想了解Java/PHP /等.开发人员完成这样的任务.
据我所知,我可以选择:
使用MigraDoc/PDFSharp并采用"代码"方式,无需任何视觉设计师
我可以使用HTML并将其转换为PDF(理论上这是最好的方法,但实际上将HTML 1:1看成是一个好看的PDF文件很糟糕)
我可以使用一些奇怪的MS Word模板/批处理的东西
胶乳?
你有什么解决方案?
我有一个发现启用WCF服务,现在我想连接客户端.
问题:当我使用udp端点(1.)并尝试以编程方式发现服务时,它可以工作......当我使用App.config方法(2.)时它不会(错误:没有发现端点).
对我而言,两种解决方案的"udp发现结果"似乎应该相同,但遗憾的是它不是......
1.以编程方式处理(工作):
码:
DiscoveryClient discClient = new DiscoveryClient("udpDiscoveryEndpoint");
FindCriteria fCriteria = new FindCriteria(typeof(IAlarmServer));
fCriteria.Duration = TimeSpan.FromSeconds(5);
fCriteria.MaxResults = 1;
FindResponse fResponse = discClient.Find(fCriteria);
EndpointAddress address = fResponse.Endpoints[0].Address;
Console.WriteLine("Address found: " + address.ToString());
Run Code Online (Sandbox Code Playgroud)
配置:
<system.serviceModel>
<client>
<endpoint name="udpDiscoveryEndpoint" kind="udpDiscoveryEndpoint" />
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
2.使用App.config和"集成到端点"方法的方法(不起作用!):
码:
var Proxy = new AlarmServerClient("IAlarmServer"); // Default client generated by Visual Studio
Proxy.SomeMethod(); // throw no endpoints discovered exception
Run Code Online (Sandbox Code Playgroud)
配置:
<standardEndpoints>
<dynamicEndpoint>
<standardEndpoint name="discoveryDynamicEndpointConfiguration">
<discoveryClientSettings>
<findCriteria duration="00:00:05" maxResults="1">
<types>
<add name="AlarmServiceRef.IAlarmServer"/>
</types>
</findCriteria> …
Run Code Online (Sandbox Code Playgroud) 我有一个类有这样的结构的类:
private static Dictionary<Contract, IPriceHistoryManager> _historyManagers = new Dictionary<Contract, IPriceHistoryManager>();
Run Code Online (Sandbox Code Playgroud)
并且让我们说两种方法:
public void AddSth()
{
_historManagers.Add(new Contract(), new PriceHistoryManager());
}
public int CountDic()
{
return _historyManagers.Count();
}
Run Code Online (Sandbox Code Playgroud)
问题: 当运行单元测试时,没有办法"重置"字典,当我用类的单独实例创建多个单元测试时,"CountDic"会给出不可预测的结果,我无法测试监听.
问题: 这通常被认为是一种"坏"的方法,如果是的话:如何做得更好/更多单位稳定?如果没有:如何最好地进行单元测试?
谢谢.
我是WPF的新手,我需要一种方法将树视图控件拉伸到完整的可用尺寸..因此,水平和垂直拉伸是我的第一个猜测,但树视图的行为类似于"自动"尺寸......
我在做某事 错了吗?
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
x:Class="WpfApplication2.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="500" Height="500"
MinWidth="500" MinHeight="500">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Orientation="Vertical">
<TreeView VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<TreeViewItem>asdasd</TreeViewItem>
<TreeViewItem>asdasd</TreeViewItem>
</TreeView>
</StackPanel>
<Label Grid.Row="1">asdasd</Label>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud) 如何使Linq查询从类别中获取所有Productpricediscounts?
public class ProductCategory
{
public List<Product> categoryProducts;
}
public class Product
{
public List<Productprice> productPrices;
}
public class Productprice
{
public List<Productpricediscount> priceDiscounts;
}
Run Code Online (Sandbox Code Playgroud)
我的查询必须看起来像:
categoryProducts.Select(p => p.productPrices).Select(x => x.?!?!
Run Code Online (Sandbox Code Playgroud)
问题是我会期待x.- intellisense建议priceDiscounts
,但我得到"list" - 值(如:"Any","Select","Distinct"等等.)
我需要LINQ来获取整个表,但这似乎不起作用...每次我通过pkey选择值时,再次触发选择..
所以,实际上这段代码:
DataContext dc = new DataContext();
dc.Stores.ToList();
Store st = dc.Stores.SingleOrDefault(p => p.Id == 124671);
Run Code Online (Sandbox Code Playgroud)
正在制作一个
select * from store
Run Code Online (Sandbox Code Playgroud)
在"ToList()"方法和附加
select * from store where id = 124671
Run Code Online (Sandbox Code Playgroud)
在它下面的选择部分......
当然,我想阻止它进行第二次选择..
我该怎么办?(我不想将ToList()结果存储在List <Store>等附加属性中
更新:
关于你的答案意味着:
Store st = stores.SingleOrDefault(p => p.Id == 124671);
Store st = stores.SingleOrDefault(p => p.Id == 124671);
Run Code Online (Sandbox Code Playgroud)
会触发2选择到DB,这会使LINQ-idea无用?!或者我在这里弄错了什么?
我认为LINQ基本上会保存所有我在选择抓起数据,并仅执行时的"缓存"未找到该数据的另一要求.所以,我认为它像某种我的应用程序之间,"神奇" storagelayer的数据库..
更新#2
只是你得到了这个想法..我想在开始时(当抓取所有数据时)失去性能并在我从"缓存"数据中选择时改回它...
在这里考虑 CMS 用例。想象一个这样的视图:
// /Home/Index.cshtml
@model object
@{
var str = "My <b>CMS</b> content with razor code: @Html.ActionLink(\"Click\", \"Home\")"
}
@Html.MyCustomRazorStringRenderer(Model)
Run Code Online (Sandbox Code Playgroud)
预期输出:
My <b>CMS</b> content with razor code: <a href="/Home/Click">Click</a>
Run Code Online (Sandbox Code Playgroud)
MyCustomRazorStringRenderer 是什么样的?它必须以某种方式做某事。就像创建/使用 ViewContext 并渲染它(就像这里:将视图渲染为字符串)但我无法完全理解它。
c# ×8
.net ×3
asp.net ×2
asp.net-mvc ×2
linq ×2
unit-testing ×2
.net-4.0 ×1
asynchronous ×1
document ×1
latex ×1
outputcache ×1
pdf ×1
plpgsql ×1
postgresql ×1
razor ×1
sql ×1
static ×1
treeview ×1
wcf ×1
wcf-binding ×1
wpf ×1