EF 导航属性的使用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ModelFirst
{
class Program
{
static void Main(string[] args)
{
Model1Container context = new Model1Container();
//Customer customer = new Customer() { CustomerName = "zhangsan", CustomerPwd = "123" };
//Order order1 = new Order() { ProductName = "apple", Customer = customer };
//Order order2 = new Order() { ProductName = "banana", Customer = customer };
//context.Customer.Add(customer);
//context.Order.Add(order1);
//context.Order.Add(order2);
//context.SaveChanges();
var customers = from c in context.Customer
select c;
foreach (var c in customers)
{
Console.WriteLine(c.CustomerName + ":");
foreach (var o in c.Order)
{
Console.WriteLine(o.ProductName);
}
}
Console.Read();
}
}
}
EF 导航属性的使用的更多相关文章
- EF导航属性会自动从已查出来的对象附加
如果新增对象导航属性对应的Id有值,其相应的导航属性会自动在内存中查找,如果存在会自动附加上去. public virtual void UpdateMaterialPurchaseOrderItem ...
- MVC EF 导航属性
@model IQueryable<EFExam.Models.CategoryProductViewModel>@{ Layout = null;}<!DOCTYPE htm ...
- ef导航属性
https://msdn.microsoft.com/en-us/data/jj574232.aspx 场景是 A表中有B,B表中又C.都是一堆多的关系.怎样Mapping是个问题啊. var ...
- ASP.NET EF 延迟加载,导航属性延迟加载
ASP.NET EF 延迟加载,导航属性延迟加载 EF(EntityFramework)原理:属于ORM的一种实现 通过edmx文件来查看三部分:概念模型,数据模型,映射关系,上下文DbConte ...
- EFCode First 导航属性
首先谈谈自己对EF的接触的过程吧,最先接触EF只是因为EF支持从数据库把关系扒下来,可以省掉自己写Select.Update.Insert这些SQL语句,而且修改非常方便,后来在使用的过程中发现导航属 ...
- .NET ORM 导航属性【到底】可以解决什么问题?
写在开头 从最早期入门时的单表操作, 到后来接触了 left join.right join.inner join 查询, 因为经费有限,需要不断在多表查询中折腾解决实际需求,不知道是否有过这样的经历 ...
- EF架构~为导航属性赋值时ToList()的替换方案
回到目录 今天在进行EF开发时,遇到一个问题,在进行join查询时,类中的一个集合类型的导航属性,在给它赋值时,将查询出来的结果ToList()后,出错了,linq to entity不支持这种操作, ...
- MVC3+EF4.1学习系列(五)----- EF查找导航属性的几种方式
文章索引和简介 通过上一篇的学习 我们把demo的各种关系终于搭建里起来 以及处理好了如何映射到数据库等问题 但是 只是搭建好了关系 问题还远没有解决 这篇就来写如何查找导航属性 和查找导航属性的几种 ...
- EF架构~过滤导航属性等,拼接SQL字符串
拼接T-SQL串,并使它具有通用性 好处:与服务器建立一次连接,给服务器发一条SQL命令,即可实现 代码如下: 1 /// <summary> 2 /// 构建Insert语句串 3 // ...
随机推荐
- mysql 序列号生成器 (自定义函数)
https://yq.aliyun.com/articles/42600 http://bbs.csdn.net/topics/360203885 http://www.tuicool.com/art ...
- SSH连接Linux的Server超时
SSH连接Linux的Server超时 http://blog.csdn.net/cheng830306/article/details/21796865
- [Angular Testing] Unit Testing -- Test component and service.
Recommend to use angular-cli to generate component and service, so we can get testing templates. ng ...
- php汉字字符串长度和截取
mb_strlen("你好123",'utf-8');//返回5 strlen("你好");//返回几我也不知道,肯定不是2,但你想要2就用上面的 substr ...
- [tmux] Reuse terminal workspaces using tmux sessions
In this lesson, we'll learn how to detach from a running tmux session and leave it running in the ba ...
- PHP移动互联网开发笔记(8)——MySQL数据库基础回顾[2]
一.数据表 为了确保数据的完整性和一致性,在创建表时指定字段名称,字段类型和字段属性外,还需要使用约束(constraint),索引(index),主键(primary key)和外键(foregin ...
- JAVA 安装JDK注意事项
在JAVA jdk安装的时候,文件夹名称最好不要有中文,有逗号,有下划线,空格等问题.这样easy出错,比方以下几个安装路径easy出错 java文件夹/jdk1.6_x86/ 这样的就是 ...
- 一入Python深似海--print
先给大家来个干货^~^,学习Python的一个好站点,http://learnpythonthehardway.org/book/ 经典样例 以下是几个老经典的样例喽,刚接触Python的能够敲一敲, ...
- 学习鸟哥的Linux私房菜笔记(12)——系统监视2
四.控制进程 kill :语法 kill [-signal] PID 向进程传送一个特定的讯号,默认为15(终结) kill -l :列出所有可以由kill传递的讯号 1 :重启进程 2 : ...
- ElasticSearch:分析器
ElasticSearch入门 第七篇:分析器 这是ElasticSearch 2.4 版本系列的第七篇: ElasticSearch入门 第一篇:Windows下安装ElasticSearch El ...