使用out外键在实体中创建关系

时间:2013-04-20 20:08:04

标签: c# sql asp.net-mvc-3 entity-framework

我正在使用代码第一种方法,基于模态和db上下文类创建数据库。问题是,当我在一个模型和下一个模型之间创建关系并运行代码时,数据库就会生​​成外键,就像它应该的那样。

我多么想要关系,没有外键。这可能与实体框架和代码第一种方法有关吗?

例如:

namespace LocApp.Models
{
    public class Location
    {
        public int id { get; set; }
        [Required]
        public string name { get; set; }
        [Required]
        public string address { get; set; }
        [Required]
        public string city { get; set; }
        [Required]
        public string country { get; set; }
        [Required]
        public string province { get; set; }
        [Required]
        public string phone { get; set; }
        public string fax { get; set; }
        public bool active { get; set; }

        public virtual ICollection<LocationAssignment> LocationAssignment { get; set; }
    }
}

与:

有关系
namespace LocApp.Models
{
    public class LocationAssignment
    {
        public int id { get; set; }
        public int locationID { get; set; }
        public int serviceID { get; set; }
        public int productID { get; set; }
        public int personID { get; set; }

        public virtual Location Location { get; set; }
        public virtual Service Service { get; set; }
        public virtual Product product { get; set; }
        public virtual Person person { get; set; }
    }
}

如您所见,此表将具有使用位置表生成的外键。如何保持这种关系 WITH OUT 生成外键?

1 个答案:

答案 0 :(得分:0)

用户触发器插入和更新并删除相对和参考表!!!但这不可爱,你必须控制应用程序中的所有东西

相关问题