我在MySQL的MVC C#应用程序中使用NHibernate.我想让多个用户访问会话.我一直在使用.InRequestScope()我的会话,但我仍然得到:
System.ObjectDisposedException:会话已关闭!对象名称:'ISession'.在NHibernate.Impl.AbstractSessionImpl.ErrorIfClosed()*
...或者当我的同事都导航到同时访问服务的同一页面时,DataReader错误.
我的IMasterSessionSource注入
Bind<IMasterSessionSource>().To<GeneralMasterSessionSource()
.InRequestScope();
Run Code Online (Sandbox Code Playgroud)
我的IContentService是我的映射得到服务的地方
//ContentService Bingings
Bind<IContentService>().To<ContentService>().InRequestScope();
Bind<ISession>()
.ToMethod(
context =>
context.Kernel.Get<IMasterSessionSource>()
.ExposeConfiguration()
.BuildSessionFactory()
.OpenSession()
)
.WhenInjectedInto<IContentService>()
.InRequestScope();
Run Code Online (Sandbox Code Playgroud)
contentService的
public interface IContentService
{
IQueryable<Question> Questions{ get; }
}
public class ContentService : IContentService
{
private readonly ISession _session;
public ContentService(ISession session)
{
_session = session;
}
public IQueryable<Question> Questions
{
get { return _session.Query<Question>(); }
}
}
Run Code Online (Sandbox Code Playgroud)
DetailsService
public interface IDetailsService
{
IEnumerable<Question> PullQuestions();
}
public class DetailsService : IDetailsService
{
private readonly IContentService …Run Code Online (Sandbox Code Playgroud) 我对 MVC 有点陌生。但我已经走了很长一段路。我将 PayPal MVC API 集成到我的项目中,当我将多个项目放入购物车并查看项目列表时,我意识到只填充了数组中的最新项目。
我一直在尝试使用这个 bu 我很容易不知道我在向 PayPal 的项目列表中添加多个项目时缺少什么。
PaymentWithCreditCard() 中有这部分:
//create and item for which you are taking payment
//if you need to add more items in the list
//Then you will need to create multiple item objects or use some loop to instantiate object
var item = new Item();
foreach (var cartitem in cookieCarts)
{
item.name = cartitem.Fullname;
item.currency = "USD";
item.price = cartitem.Price;
item.quantity = cartitem.Qty.ToString();
item.sku = cartitem.Sku;
var intPrice = Int32.Parse(cartitem.Price);
subtotal …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的字符串:
var str = "DAVID CORPORATION"
Run Code Online (Sandbox Code Playgroud)
然后我有一个我不想在str中的子串列表.
var describers = new List<string> {"CORP", "INC", "LTD", "TECH", "ENGINEER", "LLC","MICROELE"};
Run Code Online (Sandbox Code Playgroud)
然后我把str分成一个列表:
var strList = str.Split(' ').ToList();
Run Code Online (Sandbox Code Playgroud)
现在我想删除包含描述符中子字符串的列表中的所有项目.我发现这种方式在互联网上做了一百万次.
strList.RemoveAll(x => describers.Contains(x));
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为它所做的只是检查描述符是否包含strList的整个单词.我需要它反向工作.
这不起作用,但它是我希望它如何工作的算法.
strList.RemoveAll(x => x.Contains(describers.Any()));
Run Code Online (Sandbox Code Playgroud)
无法从'bool'转换为'string'
当然,但如何删除strList中包含来自描述符的子字符串项的项.
..只在linq.lamba中.我试图远离foreach/for/do循环.