#!/usr/bin/env python import sqlalchemy from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column,Integer,String,DATE,Enum,ForeignKey from sqlalchemy.orm import sessionmaker,relationshi…
现在很多ORM不自带外键关联的实体查询,比如我查询用户,用时将关联的角色信息查询出来,那么就要进行2次查询,很麻烦.而我现在要做的就是基于EF的外键关联查询.很方便的. 首先,创建基础查询的BaseService public class BaseService<T> where T : BaseEntity { public virtual int Create(T item) { using (var db = new DatabaseContext()) { db.Set<T>…
//实体类 [Table("invoiceinfo", Schema = "obs")] public class invoice { [Key] public string invoice_num { get; set; } public string merchant_id { get; set; } public DateTimeOffset? verify_time { get; set; } //one to many public virtual ILi…