using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Northwind.App.Entities { public class Account { /// /// 账户ID /// public int AccountID { get; set; } /// /// 账户名 /// public string AccountName { get; set; } /// /// 密码 /// public string Password { get; set; } /// /// 用户信息 /// public virtual User User { get; set; } } }
User.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Northwind.App.Entities { public class Account { /// /// 账户ID /// public int AccountID { get; set; } /// /// 账户名 /// public string AccountName { get; set; } /// /// 密码 /// public string Password { get; set; } /// /// 用户信息 /// public virtual User User { get; set; } } }
实体映射类:
AccountMap.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Entity.ModelConfiguration; using System.ComponentModel.DataAnnotations.Schema; using Northwind.App.Entities; namespace Northwind.App.Mapping { public class AccountMap : EntityTypeConfiguration { public AccountMap() { // Primary Key this.HasKey(t => t.AccountID); // Properties this.Property(t => t.AccountName).HasMaxLength(50); this.Property(t => t.Password).HasMaxLength(100); // Table & Column Mappings this.ToTable(“Account”); this.Property(t => t.AccountID).HasColumnName(“AccountID”); this.Property(t => t.AccountName).HasColumnName(“AccountName”); this.Property(t => t.Password).HasColumnName(“Password”); } } }
UserMap.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Entity.ModelConfiguration; using System.ComponentModel.DataAnnotations.Schema; using Northwind.App.Entities; namespace Northwind.App.Mapping { public class UserMap : EntityTypeConfiguration { public UserMap() { // Primary Key this.HasKey(t => t.AccountID); // Properties this.Property(t => t.AccountID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); this.Property(t => t.UserName).HasMaxLength(50); this.Property(t => t.Email).HasMaxLength(100); // Table & Column Mappings this.ToTable(“User”); this.Property(t => t.AccountID).HasColumnName(“AccountID”); this.Property(t => t.UserName).HasColumnName(“UserName”); this.Property(t => t.Email).HasColumnName(“Email”); this.Property(t => t.RegisterDate).HasColumnName(“RegisterDate”); // Relationships this.HasRequired(t => t.Account) .WithRequiredDependent(t => t.User); } } }
NorthwindContext.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Entity; using Northwind.App.Entities; using Northwind.App.Mapping; namespace Northwind.App { public class NorthwindContext : DbContext { static NorthwindContext() { Database.SetInitializer(new DropCreateDatabaseIfModelChanges()); } public DbSet Accounts { get; set; } public DbSet Users { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new AccountMap()); modelBuilder.Configurations.Add(new UserMap()); } } }
Program.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Northwind.App.Entities; namespace Northwind.App { class Program { static void Main(string[] args) { using (NorthwindContext db = new NorthwindContext()) { Account account = new Account { AccountName = “Test”, Password = “1” }; db.Accounts.Add(account);
User user \= new User { AccountID = account.AccountID, UserName = "测试", Email = "test@126.com", RegisterDate = DateTime.Now };
db.Users.Add(user);
db.SaveChanges();
}
}
}
}
代码运行后生成的数据库结构图:
2、EF Code First一对多关联关系
关联表:Product 产品表、Category分类表
关联关系:一个产品属于一个分类,一个分类可以有多个产品
实体代码:
Category.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Northwind.App.Entities { public class Category { /// /// 分类ID /// public Guid CategoryID { get; set; } /// /// 分类名称 /// public string CategoryName { get; set; } /// /// 产品 /// public virtual ICollection Products { get; set; } } }
Product.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Northwind.App.Entities { public class Product { /// /// 产品ID /// public Guid ProductID { get; set; } /// /// 产品名称 /// public string ProductName { get; set; } /// /// 单价 /// public decimal UnitPrice { get; set; } /// /// 数量 /// public Nullable<int> Quantity { get; set; } /// /// 库存 /// public Nullable<int> UnitsInStock { get; set; } /// /// 产品类别ID /// public Guid CategoryID { get; set; } /// /// 产品类别 /// public virtual Category Category { get; set; } } }
实体映射类:
CategoryMap.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Entity.ModelConfiguration; using System.ComponentModel.DataAnnotations.Schema; using Northwind.App.Entities; namespace Northwind.App.Mapping { public class CategoryMap : EntityTypeConfiguration { public CategoryMap() { // Primary Key this.HasKey(t => t.CategoryID); // Properties this.Property(t => t.CategoryID) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); this.Property(t => t.CategoryName).IsRequired() .HasMaxLength(100); // Table & Column Mappings this.ToTable(“Category”); this.Property(t => t.CategoryID).HasColumnName(“CategoryID”); this.Property(t => t.CategoryName).HasColumnName(“CategoryName”); } } }
ProductMap.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Entity.ModelConfiguration; using System.ComponentModel.DataAnnotations.Schema; using Northwind.App.Entities; namespace Northwind.App.Mapping { public class ProductMap : EntityTypeConfiguration { public ProductMap() { // Primary Key this.HasKey(t => t.ProductID); // Properties this.Property(t => t.ProductID) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); this.Property(t => t.ProductName).IsRequired() .HasMaxLength(100); this.Property(t => t.UnitPrice).HasPrecision(10, 2); // Table & Column Mappings this.ToTable(“Product”); this.Property(t => t.ProductID).HasColumnName(“ProductID”); this.Property(t => t.ProductName).HasColumnName(“ProductName”); this.Property(t => t.UnitPrice).HasColumnName(“UnitPrice”); this.Property(t => t.Quantity).HasColumnName(“Quantity”); this.Property(t => t.UnitsInStock).HasColumnName(“UnitsInStock”); this.Property(t => t.CategoryID).HasColumnName(“CategoryID”); // Relationships this.HasRequired(t => t.Category) .WithMany(t => t.Products) .HasForeignKey(t => t.CategoryID) .WillCascadeOnDelete(false); } } }
NorthwindContext.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Entity; using Northwind.App.Entities; using Northwind.App.Mapping; namespace Northwind.App { public class NorthwindContext : DbContext { static NorthwindContext() { Database.SetInitializer(new DropCreateDatabaseIfModelChanges()); } public DbSet Accounts { get; set; } public DbSet Users { get; set; } public DbSet Categories { get; set; } public DbSet Products { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new AccountMap()); modelBuilder.Configurations.Add(new UserMap()); modelBuilder.Configurations.Add(new CategoryMap()); modelBuilder.Configurations.Add(new ProductMap()); } } }
Program.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Northwind.App.Entities; namespace Northwind.App { class Program { static void Main(string[] args) { using (NorthwindContext db = new NorthwindContext()) { Category category = new Category { CategoryName = “手机数码” }; db.Categories.Add(category);
public async Task<bool> Add(string name) { var teacher = new Teacher { Name = "teacher one" }; _unitOfWork.RegisterNew(teacher); await _unitOfWork.CommitAsync();
var student = new Student { Name = name, TeacherId = teacher.Id }; _unitOfWork.RegisterNew(student); await _unitOfWork.CommitAsync();
TaskThread::Entry调用Task::Run方法来完成对应的Task,Task::Run方法的返回值类型是SInt64,也即signedlong long int类型。TaskThread::Entry根据Task::Run方法的返回值进行不同的处理。对于小于0的返回值,需delete这个Task;对于大于0的返回值,返回值代表了下次处理这个Task需等待的时间,TaskThread::Entry调用fHeap.Insert(&theTask->fTimerHeapElem)把Task插入到堆里,并设定等待时间。对于等于0的返回值,TaskThread::Entry不再理会该Task。
from django.contrib.auth.backends import ModelBackend class ShopModelBackend(ModelBackend): def authenticate(self, request, username=None, password=None, **kwargs): try: if re.match('^1[3-9]\d{9}$', username): user = User.objects.get(mobile=username) else: user = User.objects.get(username=username) except: return None else: if user.check_password(password): return user else: return None
from django.shortcuts import render from django.views import View from django import http from QQLoginTool.QQtool import OAuthQQ from django.conf import settings
from django.shortcuts import render from django.views import View from django import http from QQLoginTool.QQtool import OAuthQQ from django.conf import settings from .models import OAuthQQUser
<span></span><code><span># </span>docker<span> </span>run<span> </span>-it<span> </span>-p<span> </span><span>8080</span>:80<span> </span>e9d<span> </span>apache2 <span>AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.1. Set the 'ServerName' directive globally to suppress this message</span>
<span># </span>docker<span> </span>run<span> </span>-it<span> </span>-p<span> </span><span>8080</span>:80<span> </span>e9d<span> </span>/bin/bash <span>root@0123456789ab:/var/www/html# </span>apache2 <span>AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message</span> </code>
<span></span><code>-d, --detach=false Run container in background and print container ID -i, --interactive=false Keep STDIN open even if not attached -P, --publish-all=false Publish all exposed ports to random ports -p, --publish=[] Publish a container's port(s) to the host -t, --tty=false Allocate a pseudo-TTY --name string Assign a name to the container </code>
The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.
CMD [“executable”,”param1”,”param2”] (exec form, this is the preferred form)
CMD [“param1”,”param2”] (as default parameters to ENTRYPOINT)
Return low-level information on a container, image or task
-f, --format Format the output using the given go template --help Print usage -s, --size Display total file sizes if the type is container --type Return JSON for specified type, (e.g image, container or task) </code>