具有多个表(父&子&子子)MVC 3的模型类 [英] model class with multiple tables (parent & child & sub child) MVC 3
问题描述
我正在使用MVC4 r.
我希望有一个包含3个事务表的单一模型类,以便在创建强类型的创建页面时可以在数据条目中显示3个表(txn_RequestForm,txn_list_IndividualUser,txn_list_MultipleUsers er).
1. list_ddlRequestType RequestTypeID 1(个人用户)& 2(多个用户)
2. txn_RequestForm(RequestID)PK:
3. txn_list_IndividualUser(RequestID)FK
4. txn_list_MultipleUsers(RequestID)FK网格
Hi,
I am using MVC4 r.
I wanted to have single model class that contains 3 transactional tables so that when I create strongly-typed create page I can display in the data entry the 3 tables (txn_RequestForm , txn_list_IndividualUser, txn_list_MultipleUsers er).
1. list_ddlRequestType RequestTypeID 1(Individual User) & 2 (Multiple User)
2. txn_RequestForm (RequestID) PK :
3. txn_list_IndividualUser (RequestID) FK
4. txn_list_MultipleUsers (RequestID) FK grid
txn_RequestForm
RequestID (PK) RequestTypeID (FK) ContactNumber
1 1 5566
2 2 5567
3 2 1234
txn_list_IndividualUser
RequestID (FK) |EmpNo |FirstName |LastName |EmailAdd
1 |105514 |Juan |Pedro |juan.email@teSTmvc.COM
1 |105515 |Juan_2 |Pedro_2 |juan.email2@teSTmvc.COM
txn_list_MultipleUsers
RequestID(FK) MUserID NameSurname PurposeID MPositionTitle
3 |43211 |Joshua_1 |_1 |_Test
3 |43212 |Joshua_2 |_2 |_Test
3 |43213 |Joshua_3 |_3 |_Test
在此先谢谢您.
Thanks in advance.
推荐答案
您只能将网格类型控件指向单个数据源.所以会带您需要创建一个封装你正在谈论(采摘从T2或T3作为相应的行并暴露出相应类型的列表或可查询的)行为的模型类.
如果您拥有数据库的控制权,并且如果T2和T3具有相同的架构,那么您可能要考虑使它们成为具有类型转换列的单个表.然后,您仅可以基于ID和类型从T1进行常规外键查找,而不是基于ID进行查找,然后在不同表的行之间进行切换.数据库模型并不是真正设计用来做到这一点的.
You can only point a grid type control at a single data source. So you''ll need to create a model class that encapsulates the behaviour you are talking about (picking rows from T2 or T3 as appropriate and exposing a List or Queryable of the appropriate type).
If you have control of the database, if T2 and T3 have the same schema then you probably want to consider making them a single table with a type-switching column. Then you can just do a normal foreign key lookup from T1 based on ID and type, instead of doing a lookup based on ID and then switching between rows from different tables. The database model isn''t really designed to do that.
这篇关于具有多个表(父&子&子子)MVC 3的模型类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!