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

 

 

转载于:https://www.cnblogs.com/goodlucklzq/p/4442221.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值