我正在动态生成代码,目前正在使用String.Format和嵌入占位符 - 但重新格式化C#代码以用作模板是一件痛苦的事情,我认为使用T4模板会更好.
但是,代码生成将在正在运行的系统上进行,因此我需要知道我可以安全合法地将Microsoft T4引擎与我的产品一起重新分发.
其他人这样做了吗?或者知道(合法)答案?
我正在评估对现有模式使用EF - 问题是我无法弄清楚如何在外键不是主表的主键的表之间建立关联.
作为一个例子,a foo可能有许多bars像这样的定义(原谅伪代码):
table foo {
int foo\_id pk,
char(10) foo\_code,
...
}
table foobar {
int bar\_id pk,
char(10) bar\_foo\_code fk(foo.foo\_code),
...
}
Run Code Online (Sandbox Code Playgroud)
我缺少什么能够创建foo_foobar关联,因此Bars在Foo实体上创建导航属性?
这是场景:
我在"Groups"和"Users"之间建立了一个关联,由"UserGroupAssignment"对象表示.
public class UserGroupAssignment
{
[Key]
public virtual long Id { get; set; }
[Association("UserAssignmentToUser", "UserId", "Id", IsForeignKey = true)]
public virtual User { get; set; }
[Association("UserAssignmentToGroup", "GroupId", "Id", IsForeignKey = true)]
public virtual Group { get; set; }
public virtual bool IsPrimary { get; set; }
public virtual DateTime? ValidFrom { get; set; }
public virtual DateTime? ValidTo { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有两个业务逻辑方法,GetUserAssignmentsForGroups和GetGroupAssignmentsForUsers,我返回分配,分别填充用户和组属性.即GetUserAssignmentsForGroup接受GroupId并返回该组的分配,并填充User属性.
我想要的是将这两个方法公开为域查询方法,如下所示:
[Query]
public IQueryable<UserGroupAssignment> GetAssignmentsForGroupWithUsers(long groupId)
{
return this.businessLogic.GetUserAssignmentsForGroups(groupId);
}
[Query]
public IQueryable<UserGroupAssignment> …Run Code Online (Sandbox Code Playgroud) 我现在已经用这一块撞墙了.
我有一个派生自ContentControl的自定义控件 - 它完美地工作除了它不会调整大小以适应其父级,无论是以声明方式还是以编程方式.
自定义控件是(最终)内容演示者的父级,并且大小正确,但我的控件不会自行调整大小.
(sample.MyControl) - 400x267
- (System.Windows.Controls.ContentPresenter) - 979x569
Run Code Online (Sandbox Code Playgroud)
即使我明确设置了宽度和高度(在合适的时刻),尺寸也不会"粘住"
Debug.WriteLine(string.Format("MyControl {0}: Size is {1}x{2} ({3}/{4})",
GetHashCode(), this.ActualWidth, this.ActualHeight,
this.HorizontalAlignment, this.VerticalAlignment));
Debug.WriteLine(string.Format("Parent is {0}x{1} ({2}/{3})",
parent.ActualWidth, parent.ActualHeight,
parent.HorizontalAlignment, parent.VerticalAlignment));
this.Width = parent.ActualWidth;
this.Height = parent.ActualHeight;
Debug.WriteLine(string.Format("MyControl {0}: New size is {1}x{2}",
GetHashCode(), this.ActualWidth, this.ActualHeight));
Run Code Online (Sandbox Code Playgroud)
上面的代码给出:
MyControl 36022757: Size is 400x267 (Stretch/Stretch)
Parent is 979x569 (Stretch/Stretch)
MyControl 36022757: New size is 400x267
Run Code Online (Sandbox Code Playgroud)
为什么!哦天哪,为什么!
有人有任何想法吗?