zoukankan      html  css  js  c++  java
  • .Net 入门资料推荐 (编辑中)

    1.首先推荐 网易云课堂上的一个付费课程:常老师带你学ASP.NET MVC ,价格199元

    2. 一个.net的框架,ABP,中文介绍如下 http://www.cnblogs.com/farb/p/ABPTheory.html

    3.经常遇到的ajax跨域请求的资源共享问题,参见这里http://www.ruanyifeng.com/blog/2016/04/cors.html

    3 entityframework 的 数据库更新命令 https://www.cnblogs.com/panchunting/p/entity-framework-code-first-migrations.html

    4.entityframework 必须知道的 fluent api 使用方法 https://www.cnblogs.com/caofangsheng/p/5715876.html

    这里我想说一下自己的心得,entity framework 有一定的智能,可以创建表与表之间的关联关系。

    比如:

    下面这个一对多关系

     public class Proposal : AggregateRoot<int>
        {
            
    
            public virtual List<ServiceType> ServiceTypes { get; set; }
    }
    
     public class ServiceType : Entity<long>
        {
    
           public virtual string Name { get; set; }
        
        }

    系统会自动向 servicetype表中,加入外键 Proposal_Id列,完成关联,调用proposal.ServiceTypes 是没问题的。

    但是下面这个就不行,不能调用proposal.requestor 会提示缺少外键关联:

     public class Proposal : AggregateRoot<int>
        {
            
            [ForeignKey("Requestor_Id")] //没有这个关联,proposal.requestor 就会出错
            public virtual User Requestor { get; set; }
    }
    
     public class User : AggregateRoot<int>
        {
            public virtual string Name { get; set; }
       
        }

    其实,这是一个一对多关系,一个user对应多个proposal,系统也会自动在Proposal表中加入 Requestor_Id 外键,去关联user。但是系统没有将

    Requestor属性和 Requestor_Id 外键 自动对应,需要我们手动对应,加入map。

    我觉得,在使用List等集合的时候,可以不做处理,但是如果直接使用其他数据库对象类型作为属性,就要进行手动的map操作,比如这里的 requestor。
    原因不是特别明白,等研究一下文档。
  • 相关阅读:
    virtual方法和abstract方法的使用(轉載)
    C# 如何寫入cookie
    Literal的一般用法,与Label对比 MSDN上的解释
    With temp as---sql语句用法 转
    GridView __DataKey 使用
    .net里radiobutton 两个怎么才能让他只选择一个
    Server.Transfer()与Response.Redirect()区别
    OnInit 事件
    ajax中Sys.WebForms.PageRequestManager的事件激发顺序
    Linux CentOS 查看某个进程打开的文件(文件描述符)
  • 原文地址:https://www.cnblogs.com/breezemist/p/7871686.html
Copyright © 2011-2022 走看看