zoukankan      html  css  js  c++  java
  • Web API零碎知识

    查看EF生成的sql的方法

    1.通过在context中设置可以追踪EF【版本必须是6.0或以上】中生成的sql

    public BookServiceContext() : base("name=BookServiceContext")
    {
        // 当然也可以输出到其它位置
        this.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
    }

    2.通过使用sqlserver profiler监测RPC completed事件

    3.使用vs中debug菜单下的IntelliTrace工具,在调试时可以监测到ADO.NET事件

     

    下面的Book类与Author类构成互相引用,在序列化时会遇到“Self referencing loop detected with type 'BookService.Models.Book‘”问题

     1     public class Book
     2     {
     3         public int Id { get; set; }       
     4         public decimal Price { get; set; }
     5         public string Genre { get; set; }
     6 
     7         // Foreign Key
     8         public int AuthorId { get; set; }
     9         // Navigation property
    10         public Author Author { get; set; }
    11     }
    12    
    13     public class Author
    14    {
    15     public int AuthorId { get; set; }
    16     [Required]
    17     public string Name { get; set; }
    18 
    19     public ICollection<Book> Books { get; set; }
    20   }
    View Code

    解决方案:

    1. 使用DTOs
    2. 配置XML或Json的序列化器,使其能够处理循环引用

    Model-View-ViewModel(MVVM)模式:

    • model 代表服务端的业务数据
    • view  表示层(html)
    • view model 是JavaScript对象持有的model

     

  • 相关阅读:
    面向过程,面向对象三大特性
    JDBC连接数据库
    java线程
    ssm
    com组件方面的书籍
    剑雨
    JavaScript为元素动态添加事件之(attachEvent||addEventListener)
    Opacity多浏览器透明度兼容处理
    通过U盘安装Windows 7
    蜀门Online 简单打怪脚本(vbs)
  • 原文地址:https://www.cnblogs.com/goodlucklzq/p/4442221.html
Copyright © 2011-2022 走看看