小编Nev*_*ynh的帖子

JSON.NET错误检测到类型的自引用循环

我试图序列化从实体数据模型.edmx自动生成的POCO类,当我使用时

JsonConvert.SerializeObject 
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

错误发生类型System.data.entity检测到的自引用循环.

我该如何解决这个问题?

serialization json json.net

458
推荐指数
9
解决办法
27万
查看次数

如何解决只能从脚本中调用类定义中具有[ScriptService]属性的Web服务

当在webservice中使用Jquery AJAX调用方法时,我尝试使用从实体数据模型生成的webservice返回POCO类作为JSON.但我有错误的问题"只能从脚本中调用类定义上有[ScriptService]属性的Web服务",并且卡在其中,

这是我的代码:

namespace CarCareCenter.Web.Admin.Services
{
    /// <summary>
    /// Summary description for About
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class About : System.Web.Services.WebService
    {
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod]
        public static Entities.Category getAbout()
        {
            Entities.Category about = new Entities.Category();
            using (var context = new CarCareCenterDataEntities())
            {
                about = (from c in context.Categories where c.Type == "About" select …
Run Code Online (Sandbox Code Playgroud)

error-handling web-services

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

如何使用Jquery编写点击事件?哪种方式是正确的?

我是Jquery的新手.我的代码有问题,在为click事件编写jquery代码时,我很困惑.请帮助我并提前解释感谢!

第一种方法:

<script type="text/javascript">

$('a').click(function(){ 
    alert('you clicked a tag !!! ');
});

</script>
Run Code Online (Sandbox Code Playgroud)

和第二种方法:

<script type="text/javascript">
        $(document).ready(function(){
            $('a').click(function(){ 
                alert('you clicked a tag !!! ');
            });
        });

</script>
Run Code Online (Sandbox Code Playgroud)

当我编写2个测试方法时,只有第二个方法成功并显示警报,但第一个没有做任何事情.另外我在http://api.jquery.com/click/上查看第一个是他们编写样本的方式,但它运行成功,这让我感到困惑.

<script>
    $("p").click(function () { 
      $(this).slideUp(); 
    });
    $("p").hover(function () {
      $(this).addClass("hilite");
    }, function () {
      $(this).removeClass("hilite");
    });
</script>
Run Code Online (Sandbox Code Playgroud)

jquery

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

如何在Linq-to-Entities查询中使用DateTime.AddXXXX函数?

我想AddMonths在查询中使用

List<Entities.Subscriber> items = (from s in context.Subscribers
                 where s.Validated == false && s.ValidationEmailSent == true && s.SubscriptionDateTime < DateTime.Now.AddMonths(-1)
                 select s).ToList();
Run Code Online (Sandbox Code Playgroud)

但我收到一个错误:

LINQ to Entities无法识别方法'System.DateTime AddMonths(Int32)'方法,并且此方法无法转换为存储表达式.

有没有办法在我的查询中使用这个功能?

c# linq linq-to-entities entity-framework

0
推荐指数
2
解决办法
3650
查看次数