我在MVC项目中使用EF 4.1和代码优先,而AutoMapper将实体映射到视图模型.
在使用代码优先之前,我能够排除导航属性,以防止加载任何尚未加载的内容.我在我的查询中使用.Include()来包含我需要的引用,以避免额外的数据库往返.
但是,使用代码优先,我的实体只公开实体属性(如果有多个,则显示ICollection).如何在不触发负载的情况下知道是否已加载?
假设可以这样做,有没有办法使这成为AutoMapper的默认行为,这样我就不必在每个实体上明确排除成员?
c# entity-framework automapper ef-code-first entity-framework-4.1
我正在开发一个ASP.NET MVC解决方案,它有许多不同的菜单.要显示的菜单取决于当前登录用户的角色.
在MVC 3中,我有一些自定义代码来支持这种情况,通过使用单个控制器方法返回正确的菜单.它会通过将请求推迟到适当的控制器和操作来执行此操作,具体取决于当前用户.
此代码似乎在MVC 4中被破坏,我正在寻找帮助来解决它.
首先,我添加了一个TransferResult助手类来执行重定向:
public class TransferResult : RedirectResult
{
#region Transfer to URL
public TransferResult( string url ) : base( url )
{
}
#endregion
#region Transfer using RouteValues
public TransferResult( object routeValues ) : base( GetRouteUrl( routeValues ) )
{
}
private static string GetRouteUrl( object routeValues )
{
var url = new UrlHelper( new RequestContext( new HttpContextWrapper( HttpContext.Current ), new RouteData() ), RouteTable.Routes );
return url.RouteUrl( routeValues );
}
#endregion
#region Transfer using ActionResult …Run Code Online (Sandbox Code Playgroud) 是否有一种方法(反射或其他方式)以编程方式确定IList接口需要ICollection,而ICollection又需要IEnumerable?
我正在研究一个反射库,并遇到了一个我可以使用这些信息的场景,但却找不到获取它的方法.编译器和IDE(显然)都知道这种关系,因此它必须以某种方式可用.
我希望得到不涉及IL或源解析的建议,这两者都不是我的用例的选项.
我一直在为我的应用程序中的所有类型和数据结构定义TypeScript接口,并且很快将面临将大多数数据结构复制为Mongoose模式定义的任务.
我想知道是否有人已经制定了一个解决方案来自动生成一个来自另一个?
我想避免维护两份本质上相同的东西的负担.
我们正在调查 EF 6.1.3 运行缓慢的性能问题,我们无法弄清楚可能是什么原因造成的。
数据库上下文初始化为:
Configuration.ProxyCreationEnabled = false;
Configuration.AutoDetectChangesEnabled = false;
Configuration.ValidateOnSaveEnabled = false;
Run Code Online (Sandbox Code Playgroud)
我们已将性能问题隔离为以下方法:
protected virtual async Task<long> UpdateEntityInStoreAsync(T entity,
string[] changedProperties)
{
using (var session = sessionFactory.CreateReadWriteSession(false, false))
{
var writer = session.Writer<T>();
writer.Attach(entity);
await writer.UpdatePropertyAsync(entity, changedProperties.ToArray()).ConfigureAwait(false);
}
return entity.Id;
}
Run Code Online (Sandbox Code Playgroud)
changedProperties 列表中有两个名称,EF 正确生成了一个更新语句,只更新这两个属性。
This method is called repeatedly (to process a collection of data items) and takes about 15-20 seconds to complete.
If we replace the method above with the following, execution time drops to 3-4 seconds: …
c# ×4
asp.net-mvc ×1
automapper ×1
c#-4.0 ×1
html ×1
html5 ×1
mongoose ×1
reflection ×1
t4mvc ×1
typescript ×1