查询与Linq有很多关系

时间:2017-02-05 16:50:52

标签: c# entity-framework linq

我在User和Clinic表之间的数据库中定义了多对多的关系。数据库没有使用EF创建,但我使用EF生成了DB模型类。 M-M关系通常使用EF创建,具有在这些类中定义的链接类的集合对象属性,但在这里我有间接关系。 User和Clinic模型都有UserClinic集合对象,而不是直接指向另一个类。

这里是如何定义数据对象的:

用户

    public User()
    {
        this.UserClinics = new HashSet<UserClinic>();
    }

    public long UsersID { get; set; }
    public string AspNetUsersID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Organization { get; set; }
    public string Title { get; set; }
    public Nullable<System.DateTime> CreateDT { get; set; }
    public Nullable<long> CreateBy { get; set; }
    public Nullable<System.DateTime> UpdateDT { get; set; }
    public Nullable<long> UpdateBy { get; set; }
    public string Type { get; set; }
    public string LoginID { get; set; }

    public virtual AspNetUser AspNetUser { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<UserClinic> UserClinics { get; set; }
}

诊所

public Clinic()
    {
        this.UserClinics = new HashSet<UserClinic>();
        this.Patients = new HashSet<Patient>();
    }

    public long ClinicID { get; set; }
    public Nullable<long> NetworkID { get; set; }
    public string Name { get; set; }
    public string Address { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string ZipCode { get; set; }
    public Nullable<System.DateTime> CreateDT { get; set; }
    public Nullable<long> CreateBy { get; set; }
    public Nullable<System.DateTime> UpdateDT { get; set; }
    public Nullable<long> UpdateBy { get; set; }

    public virtual Network Network { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<UserClinic> UserClinics { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Patient> Patients { get; set; }
}

UserClinic

public partial class UserClinic
{
    public long UsersID { get; set; }
    public long ClinicID { get; set; }
    public Nullable<System.DateTime> CreateDT { get; set; }
    public Nullable<long> CreateBy { get; set; }
    public Nullable<System.DateTime> UpdateDT { get; set; }
    public Nullable<long> UpdateBy { get; set; }

    public virtual Clinic Clinic { get; set; }
    public virtual User User { get; set; }
}

查询对象的最佳方式是什么,所以我得到的结果是:

var cliniclist = user.clinics.toList();

var user.clinics.Add(clinicList);

1 个答案:

答案 0 :(得分:1)

要选择,您只需选择template<class T> class Example: public: Example() : myptr(make_shared<Example<T>>), val(0) {} private: shared_ptr<Example<T>> myptr; T val; 集合,然后从中选择let theVC = self.viewController?.storyboard?.instantiateViewController(withIdentifier: "TrumpVC") as! TrumpViewController self.viewController?.navigationController?.pushViewController(theVC, animated: true) self.viewController?.removeFromParentViewController() self.viewController?.dismiss(animated: true, completion: nil) self.view?.presentScene(nil) 属性:

void printName(char *pointer, int size)
{
    for (i = 0; i < size; ++i)
        printf("Value: %d, addr: %p\n", pointer[i], pointer + i);
}

添加:

UserClinics