I'm working on an MVC.NET application that uses several database tables that have composite keys. What's the best way to map these composite keys in my ORMs? My first thought was to use dictionary fields i.e. classKey AS dictionary(of string, string). This seems to work ok, but complicates the parameters of my controller methods...especially when going from the client to the controller. Then I thought use a string as the "Id" property in my objects models and create hashes out of the composite keys at the controller level to populate the Ids...not sure if I like this either. Your thoughts?
我正在使用一个MVC.NET应用程序,该应用程序使用具有复合键的多个数据库表。在我的ORM中映射这些复合键的最佳方法是什么?我的第一个想法是使用字典字段,即classKey AS字典(字符串,字符串)。这似乎工作正常,但使我的控制器方法的参数复杂化...尤其是从客户端到控制器时。然后我想在我的对象模型中使用一个字符串作为“Id”属性,并在控制器级别的复合键中创建哈希以填充ID ...不确定我是否喜欢这个。你的想法?
1 个解决方案
#1
1
Let's assume your composite key is (string a, int b). Then you could write your action like this:
假设你的复合键是(字符串a,int b)。然后你可以像这样编写你的动作:
ActionResult Index(string a, int b) { }
or
class MyCompositeKey { string a; int b; }
ActionResult Index(MyCompositeKey id) { }
#1
1
Let's assume your composite key is (string a, int b). Then you could write your action like this:
假设你的复合键是(字符串a,int b)。然后你可以像这样编写你的动作:
ActionResult Index(string a, int b) { }
or
class MyCompositeKey { string a; int b; }
ActionResult Index(MyCompositeKey id) { }