自动增量列不是标识列 [英] Auto increment a column that is not an identity column

查看:85
本文介绍了自动增量列不是标识列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个项目中,我已经设置了项目 ProjectMembers ,使得项目可以有一个之间的关系ProjectMembers和ProjectMemebers列表只能参加一个项目(见<一href=\"http://stackoverflow.com/questions/31783974/concurrency-check-on-an-icollection-during-add\">Concurrency检查的ICollection的(加时))。

In a project, I have set up a relation between Project and ProjectMembers such that a Project can have a list of ProjectMembers and ProjectMemebers can only participate in one project (see Concurrency Check on an ICollection (during add)).

我想有一个字段是自动递增,但是,它不应该是一个标识列。

I would like to have a field that is auto-incremented, however, it shouldn't be an identity column.

例如,给定一个项目,一旦我们添加一个新的ProjectMemeber,该成员将收到一些(类似身份证),使我们能够识别,只有ProjectMemeber在特定的项目。

For example, given a Project, once we add a new ProjectMemeber, that member will receive a number (like an id) that allows us to identify that ProjectMemeber only in that particular Project.

有没有办法实现这个使用EF?

Is there any way to achieve this using EF?

推荐答案

我将有三个实体 - 项目成员,和一个用于名为 ProjectMembers

I would have three entities - Projects, Members, and one used as a relationship proxy called ProjectMembers.

这第三个实体只有3场 - ID 用作具有自动增量的身份,和专案编号 MEMBERID 作为ForeignKey的关系。添加唯一约束,这样MEMBERID必须是唯一的(这在强制执行上的项目成员一比一的关系)。在 ID 将是唯一在该项目的成员。当他们完成一个项目,这种关系代理记录被删除,允许重新分配到另一个项目。

This third entity has only 3 fields - id used as the Identity with autoincrement, and ProjectId and MemberId as a ForeignKey relationship. Add a unique constraint such that MemberId must be unique (which enforces the one-to-one relationship on Members in Projects). The id will be unique to that member in that project. When they finish a project, that relationship proxy record is deleted, allowing reassignment to another project.

这篇关于自动增量列不是标识列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆