[译]LightSwitch 如何实现:在查询中创建和使用全局值(Eric Erhardt)
原文标题:How Do I: Create and Use Global Values In a Query (Eric Erhardt)
在查询中使用全局值
在Visual Studio LightSwitch中可以使用的全局值基本上都是基于Date和DateTime类型的:
•Now
•Today
•End of Day
•Start of Week
•End of Week
•Start of Month
•End of Month
•Start of Quarter
•End of Quarter
•Start of Year
•End of Year
![]()
定义全局值
改为文件视图,在Data文件夹中使用 “XML (Text) Editor”对ApplicationDefinition.lsml进行编辑添加如下代码,注意要做好备份。
<?xml version="1.0" encoding="utf-8" ?> <ModelFragment xmlns="http://schemas.microsoft.com/LightSwitch/2010/xaml/model" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <GlobalValueContainerDefinition Name="GlobalDates"> <GlobalValueDefinition Name="ThirtyDaysAgo" ReturnType=":DateTime"> <GlobalValueDefinition.Attributes> <DisplayName Value="30 Days Ago" /> <Description Value ="Gets the date that was 30 days ago." /> </GlobalValueDefinition.Attributes> </GlobalValueDefinition> </GlobalValueContainerDefinition>
然后再 “Common” 项目中添加新类库文件,名称有上面代码中定义的相同,如GlobalDates。
using System; namespace ContosoSales // The name of your application { public class GlobalDates // The name of your GlobalValueContainerDefinition { public static DateTime ThirtyDaysAgo() // The name of the GlobalValueDefinition { return DateTime.Today.AddDays(-30); } } }
以上工作完成后,切换到逻辑视图,在应用程序解决方案上右击选择 “Reload Designer”.随后即可想系统内建的全局值一样使用自定义的全局值。
enjoy!
宁可追求虚无,也不能无所追求
浙公网安备 33010602011771号