使用时,Assembly.GetTypes()我会获得以此为Type.Name开头的类型<>c.....
我试图谷歌,如果这是匿名类型或其他东西.但无法得到一个非常好的答案.
Type上是否有属性表明这些类型是什么?我不喜欢这样做if(type.Name.StartsWith("<>"))
我有一个HttpModule,需要知道正在执行哪个操作.而且我需要从方法中获取MethodInfo,动作名称是不够的,我需要从类型的真实方法.
我知道如何获得控制器和动作:
string controllerName = ...RouteData.Values["controller"].ToString();
string actionName = ...RouteData.Values["action"].ToString();
Run Code Online (Sandbox Code Playgroud)
我想要做:
controllerType.GetMethod(actionName)
这当然会导致AmbiguousMatchException ...
哪个签名正在执行?有可能知道吗?
我有一个超过2000万行的表,当我这样做时:
DELETE [Table] WHERE ID = ?
Run Code Online (Sandbox Code Playgroud)
这需要40秒以上.ID列是群集的.
这是你可以期待的吗?还是可以优化这个?
我可以从Nuget控制台获得这样的列表:
Id Installed Version Latest Version
---- ----------------- ----------------
NHibernate 3.3.0.4000 3.3.3.4001
Run Code Online (Sandbox Code Playgroud)
甚至更好,对于解决方案中的所有项目?
想法?
我需要从条件查询中获取行数,并且标准按预测分组.(需要分页工作)
例如
projectionList.Add(Projections.GroupProperty("Col1"), "col1")
.Add(Projections.CountDistinct("Col2"), "Count");
Run Code Online (Sandbox Code Playgroud)
我需要避免使用CreateSQL,因为我有很多标准..而且限制等很复杂.
你能做一个子标准(分离)select count(*) from ..吗?想不通怎么样?
编辑:我通过从标准中获取sql然后修改它来解决它,以便它现在可以工作!来自条件的GetSql
我正在尝试找到在使用NHibernate的Web应用程序中处理事务的最佳解决方案.
我们使用IHttpModule,在HttpApplication.BeginRequest中我们打开一个新会话,然后用ManagedWebSessionContext.Bind(context,session)将它绑定到HttpContext; 我们关闭并取消绑定HttpApplication.EndRequest上的会话.
在我们的Repository基类中,我们总是围绕我们的SaveOrUpdate,Delete,Get方法包装一个事务,例如,根据最佳实践:
public virtual void Save(T entity)
{
var session = DependencyManager.Resolve<ISession>();
using (var transaction = session.BeginTransaction())
{
session.SaveOrUpdate(entity);
transaction.Commit();
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果您需要在某个应用程序服务中的某个位置放置一个事务来包含多个存储库调用以保存,删除等,则这不起作用.
所以我们尝试使用TransactionScope(我不想编写自己的事务管理器).为了测试这是否有效,我使用外部TransactionScope,它不会调用.Complete()来强制回滚:
存储库保存():
public virtual void Save(T entity)
{
using (TransactionScope scope = new TransactionScope())
{
var session = DependencyManager.Resolve<ISession>();
session.SaveOrUpdate(entity);
scope.Complete();
}
}
Run Code Online (Sandbox Code Playgroud)
使用存储库的块:
TestEntity testEntity = new TestEntity { Text = "Test1" };
ITestRepository testRepository = DependencyManager.Resolve<ITestRepository>();
testRepository.Save(testEntity);
using (var scope = new TransactionScope())
{
TestEntity entityToChange = testRepository.GetById(testEntity.Id);
entityToChange.Text = "TestChanged"; …Run Code Online (Sandbox Code Playgroud) 我们正在为Web应用程序运行NServiceBus来处理用户执行"批处理"操作的情况.像火一样影响1000个实体的命令..
它运行良好,但在中等负载期间我们会遇到一些死锁,这不是问题,只需重试消息..对吗?:)
当下一条消息到达并尝试打开连接时,会出现此问题.然后连接"损坏".
我们收到以下错误:System.Data.SqlClient.SqlException(0x80131904):不允许启动新请求,因为它应该带有有效的事务描述符
我在网上搜索过,我认为我们的问题是报道的NH"bug":
解决方法应该是禁用连接池.但我不喜欢这样,因为表演会降低......
我们正在运行NServiceBus 2.6,NHibernate 3.3.
有人对这个有经验么?可以升级NServiceBus吗?
(我很抱歉在这里和github都发布了这个问题,但我真的需要帮助...)
在使用Thinktecture.IdentityModel.45进行身份验证时,我无法启用CORS(System.Web.Http.Cors).
我的令牌端点有问题,我使用的是默认的"/ token".
发生的事情是,当调用/ token(来自javascript客户端)时,浏览器发出2个调用,"OPTION"调用和"/ token"资源的"GET"调用.我正在使用一个简单的PolicyProviderFactory,以便能够检查请求是否获得正确的CORS策略,它只是返回
new EnableCorsAttribute("*", "*", "*");
Run Code Online (Sandbox Code Playgroud)
第一个OPTION调用有效,GetCorsPolicyProvider被命中.另一个调用有效,但GetCorsPolicyProvider没有被命中,结果是服务器返回200 OK,包含所有正确的标题等,但内容响应为空.
我需要在路由配置中为令牌资源添加以下内容,否则我会得到"未找到".
config.Routes.MapHttpRoute(
name: "SecurityToken",
routeTemplate: "api/token");
Run Code Online (Sandbox Code Playgroud)
在所有其他请求中,OPTIONS和GET都会调用CORS策略提供程序,一切正常.我调试了thinktecture.identitymodel和相应的响应,返回正确的令牌.
/ token资源的GET方法不会调用CORS策略提供程序..但为什么呢?CorsMessageHandler已加载但从未被调用.如何判断请求是否会触发CORS/CorsMessageHandler?
诊断跟踪:
w3wp.exe Information: 0 : Request, Method=OPTIONS, Url=https://localhost/myapp/api/token, Message='https://localhost/myapp/api/token'
w3wp.exe Information: 0 : Message='CorsPolicyProvider selected: 'System.Web.Http.Cors.EnableCorsAttribute'', Operation=MyPolicyProviderFactory.GetCorsPolicyProvider
w3wp.exe Information: 0 : Message='CorsPolicy selected: 'AllowAnyHeader: True, AllowAnyMethod: True, AllowAnyOrigin: True, PreflightMaxAge: null, SupportsCredentials: True, Origins: {}, Methods: {}, Headers: {}, ExposedHeaders: {}'', Operation=EnableCorsAttribute.GetCorsPolicyAsync
w3wp.exe Information: 0 : Message='CorsResult returned: 'IsValid: True, AllowCredentials: True, PreflightMaxAge: null, AllowOrigin: https://localhost:4433, …Run Code Online (Sandbox Code Playgroud) nhibernate ×3
.net ×1
asp.net ×1
asp.net-mvc ×1
c# ×1
cors ×1
criteria ×1
deadlock ×1
nservicebus ×1
nuget ×1
performance ×1
session ×1
sql-server ×1
transactions ×1