我有一个存储过程,它使用SQL Server 2008 R2 中的MERGE 语句更新现有记录或插入单个记录(我使用 MERGE TOP(1) ..)。我使用 MERGE 的 OUTPUT 子句来发出 $action 的值以查看采取了什么操作(插入、更新、删除、'空白')。
但是,当我从 C# 程序调用我的 SP 时,我被迫执行一个读取器 (DbCommand.ExecuteReader()) 并通过它循环一次以获取 $action 值...
我的问题是,OUTPUT $action 能否以某种方式附加到 SP 输出参数,这将使我能够只执行 DbCmmand.ExecuteNonQuery() 并检查输出参数?这将使我不必实例化阅读器...
顺便说一句,我正在循环中进行此调用,因此不必实例化读取器会更快一些(我希望)
我想知道是否有人知道是否可以使用任何"开箱即用"的ASP.NET MVC3助手来生成"链接按钮"......我目前使用以下内容:
<a class="button" title="My Action" href="@Url.Action("MyAction", "MyController", new { id = item.Id })">
<img alt="My Action" src="@Url.Content("~/Content/Images/MyLinkImage.png")" />
</a>
Run Code Online (Sandbox Code Playgroud)
我试图避免使用MvcFutures,但即使我能够使用它们,我也不认为它有一个扩展方法可以实现这一点.(我相信在这种情况下的解决方案是滚动自定义帮助程序,如此处所示)
最后,这篇文章也有一个好主意通过CSS来处理这个问题,但这不是我要问的......
我最初在ServerFault.com上提出了这个问题,但在我看来,StackOverflow.com 上有更多关于 TFS 2010 的活动,所以我决定在这里重新发布它...
据我了解,“项目集合有效用户”TFS组不能再直接修改。
但是,我想授予我的所有域用户(名为“DOMAIN\Domain Users”的 Windows 组)对 TFS 项目集合的“读者”级别访问权限...
我知道我可以转到每个项目并将“DOMAIN\Domain Users”添加到 [Project]\Readers 组,但我想知道这是否可以“一次性”实现,以便将来的项目在设置时就可以访问。
我有一个可能很愚蠢的问题......我正在尝试确定键入属性的最佳方法是什么,其值为"新"或"已使用".我是否使用enum
或者我应该选择boolean
(例如IsNew)?如果我一起去enum
,我该怎么称呼这个类型和属性名称?(public NewOrUsed NewOrUsed {get; set;} < - confusing)
显然,enum
我可以拥有既不声明值(NONE,NEW,USED)又enum
更具未来性的状态(尽管可以声称其他值不存在).同样,这种类型和属性的适当名称是什么?
随着boolean
- 它非常直接(使用IsNew或IsUsed)
我知道这很愚蠢,但我很好奇其他人的想法
关心Z ..
如果您愿意enum
,请评论类型和属性的适当名称(例如public NewUsedType NewOrUsed {get; set;}
)
想象一个系统与用户,组相对应ApiControllers
.然后想象以下访问模式:
/api/users
/api/users/1
/api/users?groupId=1 <- #1 returns users belonging to group id 1 via Get(int? groupId)
/api/groups/
/api/groups/1
/api/groups/1/users <- #2 sub resource, returns users belonging to group id 1
Run Code Online (Sandbox Code Playgroud)
是否可以将#2的责任委托给#1的Get(int? groupId)
方法?
我想继续负责使用原始Controller处理子资源.换句话说,如果子资源也作为资源存在,那么子资源处理应该是什么?委托给主要资源控制员......
PS现在,我不确定上述方法是否与RESTfull样式"合作",这是完整的其他讨论......
我有AccountGroup
一个自引用实体.一片叶子AccountGroup
可以包含1个或更多Accounts
.两个实体都有Balance
财产.每个AccountGroup
具有Balance
其是一的总和Balance
在子组S或之和Balance
的所有帐户的S(在叶组的情况下).
为了构建所有AccountGroup
s和Account
s 的树列表,我必须递归地遍历这个对象图,这导致了很多(我的意思是很多!!!)对DB的调用...
是否有任何方法可以通过减少数据库调用的方式来改进这一点?
谢谢
这是修剪过的代码
public class Account
{
public int Id { get; set; }
public int GroupId { get; set; }
public string Name { get; set; }
public decimal Balance { get; set; }
public string AccountType { get; set; }
public virtual AccountGroup Group { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
public class AccountGroup
{ …
Run Code Online (Sandbox Code Playgroud) 我按照这里的公告使用最新的EF v5候选版本.我的模型是通过EntityTypeConfiguration使用映射文件...
当我尝试用枚举(drop + recreate db)替换模型上的字符串属性时,我得到了这个异常:
System.NotSupportedException was unhandled by user code
Message=The enum or spatial property 'Category' on type 'Vehicle' cannot be mapped. Use DbModelBuilderVersion 'V5_0' or later to map enum or spatial properties.
Source=EntityFramework
StackTrace:
at System.Data.Entity.ModelConfiguration.Mappers.PropertyFilter.ValidatePropertiesForModelVersion(Type type, IEnumerable`1 explicitlyMappedProperties)
at System.Data.Entity.ModelConfiguration.Mappers.PropertyFilter.GetProperties(Type type, Boolean declaredOnly, IEnumerable`1 explicitlyMappedProperties, IEnumerable`1 knownTypes)
at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapStructuralElements[TStructuralTypeConfiguration](Type type, ICollection`1 annotations, Action`2 propertyMappingAction, Boolean mapDeclaredPropertiesOnly, Func`1 structuralTypeConfiguration)
at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapEntityType(Type type)
at System.Data.Entity.DbModelBuilder.<>c__DisplayClass7.<MapTypes>b__1(Type type)
at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
at System.Data.Entity.ModelConfiguration.Utilities.IEnumerableExtensions.Each[T](IEnumerable`1 ts, Action`1 action)
at System.Data.Entity.DbModelBuilder.MapTypes(EdmModel model) …
Run Code Online (Sandbox Code Playgroud) 我在IQueryable上有一个扩展,允许传递分隔的属性名称字符串,当使用时会导致查询不构造JOIN并有效地导致SELECT N + 1问题.
我注意到的是,如果我直接从DbSet调用本机EF扩展名.Include("property"),一切正常.但是,如果我使用我的扩展(我甚至简化它只是调用.Include("property")SELECT N + 1发生...
我的问题是为什么?我究竟做错了什么?
这是调用方法(来自服务)
public MyModel[] GetAll(int page, out int total, int pageSize, string sort, string filter)
{
return _myModelRepository
.Get(page, out total, pageSize, sort, filter, "PropertyOnMyModelToInclude")
.ToArray();
}
Run Code Online (Sandbox Code Playgroud)
这是使用扩展的存储库方法
public virtual IQueryable<T> Get(int page, out int total, int pageSize, string sort, string filter = null, string includes = null)
{
IQueryable<T> query = DatabaseSet;
if (!String.IsNullOrWhiteSpace(includes))
{
//query.IncludeMany(includes); // BAD: SELECT N+1
//query.Include(includes); // BAD: SELECT N+1
}
if (!String.IsNullOrWhiteSpace(filter))
{
query.Where(filter);
} …
Run Code Online (Sandbox Code Playgroud) 我试图减少/消除我的MVC3项目中的"魔术字符串",并想知道哪种方法会更好:
使用MvcFutures并执行以下操作:
var title = "Create New Customer"; Html.ActionLink (c => c.Create(), title , new { @class = "button", title = title });
使用T4MVC
哪个选项更灵活,性能更高,重构时更容易等等?
思考?
转换类型列后是否可以获得正确的 TZ 缩写timestamptz
?
我是什么之后,SOF例子,是为了显示“2016年6月16日16:00-04:00”,在“美国/太平洋”时区与目标TZ缩写。我可以很容易地得到这个:
06/16/2016 01:00 pm
Run Code Online (Sandbox Code Playgroud)
但我无法获得以下信息:
06/16/2016 01:00 pm PDT
Run Code Online (Sandbox Code Playgroud)
一旦转换,timestamptz
就变成timestamp without timezone
,to_char
说明符 'TZ' 变得毫无意义......
这是我尝试过的示例:
SELECT
scheduled_dt AS scheduled_dt
, to_char(scheduled_dt, 'TZ') AS scheduled_dt_orig_tz
-- correct value, but missing TZ
, timezone('US/Pacific', scheduled_dt) AS schedules_dt_converted_tz
, to_char(timezone('US/Pacific', scheduled_dt), 'MM/DD/YYYY HH:MI pm') AS scheduled_dt_converted_tz_localized
-- after conversion TZ is lost
, to_char(timezone('US/Pacific', scheduled_dt), 'MM/DD/YYYY HH:MI pm TZ') AS scheduled_dt_converted_tz_localized_missing_tz
-- with cast, wrong TZ is displayed …
Run Code Online (Sandbox Code Playgroud) c# ×7
ado.net ×1
boolean ×1
database ×1
datetime ×1
dynamic-linq ×1
enums ×1
exception ×1
objectquery ×1
postgresql ×1
recursion ×1
resources ×1
rest ×1
security ×1
sql ×1
sql-server ×1
tfs ×1
timezone ×1