小编Kei*_*ows的帖子

来自实体框架的SqlException - 不允许新事务,因为会话中还有其他线程在运行

我目前收到此错误:

System.Data.SqlClient.SqlException:不允许新事务,因为会话中还有其他线程在运行.

在运行此代码时:

public class ProductManager : IProductManager
{
    #region Declare Models
    private RivWorks.Model.Negotiation.RIV_Entities _dbRiv = RivWorks.Model.Stores.RivEntities(AppSettings.RivWorkEntities_connString);
    private RivWorks.Model.NegotiationAutos.RivFeedsEntities _dbFeed = RivWorks.Model.Stores.FeedEntities(AppSettings.FeedAutosEntities_connString);
    #endregion

    public IProduct GetProductById(Guid productId)
    {
        // Do a quick sync of the feeds...
        SyncFeeds();
        ...
        // get a product...
        ...
        return product;
    }

    private void SyncFeeds()
    {
        bool found = false;
        string feedSource = "AUTO";
        switch (feedSource) // companyFeedDetail.FeedSourceTable.ToUpper())
        {
            case "AUTO":
                var clientList = from a in _dbFeed.Client.Include("Auto") select a;
                foreach (RivWorks.Model.NegotiationAutos.Client client in clientList)
                { …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework transactions inversion-of-control

571
推荐指数
10
解决办法
19万
查看次数

C# - 无法将List <Product>类型隐式转换为List <IProduct>

我有一个包含所有接口定义
的项目:RivWorks.Interfaces 我有一个项目,我定义了具体的实现:RivWorks.DTO

我之前已经完成了数百次但由于某种原因我现在收到此错误:

无法将类型'System.Collections.Generic.List <RivWorks.DTO.Product>'隐式转换为'System.Collections.Generic.List <RivWorks.Interfaces.DataContracts.IProduct>'

接口定义(缩写):

namespace RivWorks.Interfaces.DataContracts
{
    public interface IProduct
    {
        [XmlElement]
        [DataMember(Name = "ID", Order = 0)]
        Guid ProductID { get; set; }
        [XmlElement]
        [DataMember(Name = "altID", Order = 1)]
        long alternateProductID { get; set; }
        [XmlElement]
        [DataMember(Name = "CompanyId", Order = 2)]
        Guid CompanyId { get; set; }
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

具体类定义(缩写):

namespace RivWorks.DTO
{
    [DataContract(Name = "Product", Namespace = "http://rivworks.com/DataContracts/2009/01/15")]
    public class Product : IProduct
    {
        #region Constructors
        public Product() { }
        public …
Run Code Online (Sandbox Code Playgroud)

c# compiler-errors interface

82
推荐指数
3
解决办法
7万
查看次数

实体框架 - 无法将lambda表达式转换为类型'string',因为它不是委托类型

我在基于C#的代码中使用Entity Framework.我遇到了意想不到的怪异,正在寻找建议.

案例1,2,3,4 ......项目:
RivWorks.dll
RivWorks.Service.dll
RivWorks.Alpha.dll

样本(所有这些工作):
RivWorks.Alpha.dll:

public static bool EndNegotitation(long ProductID)
{
    var product = (from a in _dbFeed.AutoWithImage 
                   where a.AutoID == ProductID select a).FirstOrDefault();
...
}
Run Code Online (Sandbox Code Playgroud)

RivWorks.Service.dll

public static RivWorks.Model.NegotiationAutos.AutoWithImage 
    GetProductById(long productId)
{
    var myProduct = from a in _dbFeed.AutoWithImage 
                    where a.AutoID == productId select a;

    return myProduct.FirstOrDefault();
}
public static List<RivWorks.Model.NegotiationAutos.AutoWithImage> 
    GetProductByCompany(Guid companyId)
{
    var myProduct = from a in _dbFeed.AutoWithImage 
                    where a.CompanyID == companyId select a;

    return myProduct.ToList();
}
Run Code Online (Sandbox Code Playgroud)

等等

案例"怪异":
RivWorks.Web.Service.dll(WCF项目)
包含与其他项目相同的引用.

public …
Run Code Online (Sandbox Code Playgroud)

.net c# lambda entity-framework

72
推荐指数
5
解决办法
8万
查看次数

如何在HttpHandler中使用ASP.NET会话状态?

我有一个在客户端页面(跨域,而不是我们的IIS服务器等)上运行的HttpHandler,当他们点击我们的嵌入式链接时,它会触发我们服务器上的Handler.到目前为止一切正常.

我现在正在尝试使用System.Web.HttpContext.Session对象,但它为null.我认为它是null,因为我们在调用HttpHandler之前没有会话?多次调用处理程序会在每次调用时创建一个新会话?如果是这种情况,MS只是在调用HttpHandler时禁用了Session对象吗?谁能证实这一点?

如果是这种情况,您如何维持呼叫之间的状态?某种基于SQL的数据对象?一份文件?

TIA

httphandler session-state

56
推荐指数
3
解决办法
3万
查看次数

LINQ中的动态WHERE子句

将动态WHERE子句组装到LINQ语句的最佳方法是什么?

我在表单上有几十个复选框,并将它们传递回:Dictionary <string,List <string >>(Dictionary <fieldName,List <values >>)到我的LINQ查询.

public IOrderedQueryable<ProductDetail> GetProductList(string productGroupName, string productTypeName, Dictionary<string,List<string>> filterDictionary)
{
    var q = from c in db.ProductDetail
            where c.ProductGroupName == productGroupName && c.ProductTypeName == productTypeName
            // insert dynamic filter here
            orderby c.ProductTypeName
            select c;
    return q;
}
Run Code Online (Sandbox Code Playgroud)

c# linq dynamic where-clause

54
推荐指数
6
解决办法
11万
查看次数

EntityContainer名称必须是唯一的.已定义名为"实体"的EntityContainer

有一点背景:

我有一个DLL项目具有以下结构:

Rivworks.Model (project)  
  \Negotiation (folder)  
      Model.edmx (model from DB #1)  
  \NegotiationAutos (folder)  
      Model.edmx (model from DB #2)  
Run Code Online (Sandbox Code Playgroud)

我已将连接字符串从此项目的app.config移动到web.config文件.它们不在 ConnectionString部分中.相反,我有一个静态类,它消耗部分web.config并将它们作为AppSettings公开给我的应用程序.[settingName].

<FeedAutosEntities_connString>metadata=res://*/;provider=System.Data.SqlClient;provider connection string='Data Source=db4;Initial Catalog=RivFeeds;Persist Security Info=True;User ID=****;Password=&quot;****&quot;;MultipleActiveResultSets=True'</FeedAutosEntities_connString>
<RivWorkEntities_connString>metadata=res://*/NegotiationAutos.NegotiationAutos.csdl|res://*/NegotiationAutos.NegotiationAutos.ssdl|res://*/NegotiationAutos.NegotiationAutos.msl;provider=System.Data.SqlClient;provider connection string='Data Source=db2;Initial Catalog=RivFramework_Dev;Persist Security Info=True;User ID=****;Password=&quot;****&quot;;MultipleActiveResultSets=True'</RivWorkEntities_connString>
Run Code Online (Sandbox Code Playgroud)

我有2个类,每个上下文一个,它们看起来像这样:

namespace RivWorks.Model
{
    public class RivWorksStore
    {
        private RivWorks.Model.Negotiation.Entities _dbNegotiation;

        public RivWorksStore(string connectionString, string metadata, string provider)
        {
            EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
            entityBuilder.ConnectionString = connectionString;
            entityBuilder.Metadata = "res://*/";    // metadata;
            //entityBuilder.Provider = provider;
            _dbNegotiation = new RivWorks.Model.Negotiation.Entities(entityBuilder.ConnectionString);
        }

        public RivWorks.Model.Negotiation.Entities NegotiationEntities() …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework exception-handling visual-studio

38
推荐指数
4
解决办法
4万
查看次数

在控制台模式下运行Windows服务?

我在https://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/4d45e9ea5471cba4/4519371a77ed4a74?hl=en&pli=1上发布了一些示例代码, 用于自行安装Windows服务.我在fx 4.0的C#中.试图找出我离开轨道的地方......

我的问题:

  1. 我创建了一个Win Service项目.在program.cs/main()中,我几乎复制了代码示例.如果我处于DEBUG模式(当然是传入-c),看起来除了启动控制台窗口之外,大多数工作都会正常工作 .由于某种原因,控制台窗口永远不会打开
  2. 我遇到的另一个挑战是控制台部分中对StartUp()/ ShutDown()的调用无法编译.我最终必须初始化我的服务对象,然后调用它.
  3. 调用Console.ReadKey()方法时,我收到以下错误:

当应用程序没有控制台或从文件重定向控制台输入时,无法读取密钥.试试Console.Read.

我的代码和东西:

我的项目结构的图像:

http://screencast.com/t/zVjqkmoED

注意:在DEBUG模式下,我在TestHarness中复制了启动顺序.如果/当我开始工作时,我会从解决方案中删除它.图书馆项目是我的大多数代码所在的地方.

Program.cs中

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.ComponentModel;
using System.Configuration.Install;
using System.Collections;
using RivWorks.FeedHandler.Service;

namespace RivWorks.FeedHandler
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static int Main(string[] args)
        {
            bool install = false, uninstall = false, console = false, rethrow = false;

            try
            {
                foreach (string …
Run Code Online (Sandbox Code Playgroud)

console windows-services c#-4.0

31
推荐指数
1
解决办法
2万
查看次数

C# - 实体框架 - mscorlib.dll中发生未处理的"System.StackOverflowException"类型异常

mscorlib.dll中发生未处理的"System.StackOverflowException"类型异常
确保您没有无限循环或无限递归.

以下代码在此方法成功时调用:

internal static List<RivWorks.Model.Negotiation.ProductsSold> GetProductsSoldByCompany(Guid CompanyID)
{
    var ret = from a in _dbRiv.ProductsSold where a.Company.CompanyId == CompanyID select a;
    return ret.ToList();
}
Run Code Online (Sandbox Code Playgroud)

在返回时,它调用实体模型并尝试填充所有外键控对象(子对象).架构是[1公司有0到多个ProductsSold].出于某种原因,对以下代码的调用只会自行级联:

[global::System.Data.Objects.DataClasses.EdmRelationshipNavigationPropertyAttribute("RIV_Model", "FK_ProductsSold_Company", "Company")]
[global::System.Xml.Serialization.XmlIgnoreAttribute()]
[global::System.Xml.Serialization.SoapIgnoreAttribute()]
[global::System.Runtime.Serialization.DataMemberAttribute()]
public Company Company
{
    get
    {
        return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference<Company>("RIV_Model.FK_ProductsSold_Company", "Company").Value;
    }
    set
    {
        ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference<Company>("RIV_Model.FK_ProductsSold_Company", "Company").Value = value;
    }
}
/// <summary>
/// There are no comments for Company in the schema.
/// </summary>
[global::System.ComponentModel.BrowsableAttribute(false)]
[global::System.Runtime.Serialization.DataMemberAttribute()]
public global::System.Data.Objects.DataClasses.EntityReference<Company> CompanyReference
{
    get
    {
        return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference<Company>("RIV_Model.FK_ProductsSold_Company", "Company");
    }
    set
    {
        if ((value …
Run Code Online (Sandbox Code Playgroud)

c# stack-overflow recursion entity-framework

23
推荐指数
1
解决办法
4万
查看次数

WCF - (504)服务器未返回此请求的响应

我有一个JSONP WCF端点,我试图找出为什么我得到504错误.

HTTP/1.1 504 Fiddler - 接收失败
内容类型:text/html
连接:close
时间戳:11:45:45:9580
ReadResponse()失败:服务器未返回此请求的响应.

我可以在我的Endpoint内部的任何地方设置一个断点,逐步执行代码,看到它成功收集响应所需的数据,点击最后一行代码,然后一旦我退出WCF调用,我就得到504错误. 这是在上周工作!

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceContract(Name = "NegotiateService", Namespace = "http://rivworks.com/Services/2009/01/15")]
public class NegotiateService //: svcContracts.INegotiateService
{
    public NegotiateService() { }

    [OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    public dataObjects.NegotiateSetup GetSetup(string method, string jsonInput)
    {
        dataObjects.NegotiateSetup resultSet = new dataObjects.NegotiateSetup();

        using (RivFeedsEntities1 _dbFeed = new FeedStoreReadOnly(AppSettings.FeedAutosEntities_connString, "", "").ReadOnlyEntities())
        {
            using (RivEntities _dbRiv = new RivWorksStore(AppSettings.RivWorkEntities_connString, "", "").NegotiationEntities())
            {
                // Deserialize the input and get all the data we need...
                Newtonsoft.Json.Linq.JObject o = …
Run Code Online (Sandbox Code Playgroud)

c# asp.net wcf http-status-code-504

22
推荐指数
3
解决办法
4万
查看次数

JQuery - 将更改事件添加到下拉列表

我下拉的基础HTML有可能改变,我试图使用.live选项而不是.change选项来设置它.它对我不起作用.

我现在拥有的是:

$("#ItemsPerPage").change(function(e) { return updatePaging(); });
Run Code Online (Sandbox Code Playgroud)

不幸的是,如果我通过$.ajax它更新此控件会丢失事件定义.我尝试过但不起作用的是:

$("#ItemsPerPage").live("change", function(e) { return updatePaging(); });
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

jquery

17
推荐指数
1
解决办法
6万
查看次数