实体框架 - 代码优先映射问题(Entity Framework - Code First mapping issue)
是否可以根据特定列值进行外键映射。
我有以下实体。
public class Controller { [Key] public int Id { get; set; } public string Name { get; set; } public virtual List<ControllerDevice> ActiveDevices { get; set; } public virtual List<ControllerDevice> TamperedDevices { get; set; } public virtual List<ControllerDevice> IgnoredDevices { get; set; } } public class ControllerDevice { public int Id { get; set; } public DeviceStatus Status { get; set; } public int ControllerId { get; set; } public int NetworkDeviceId { get; set; } public virtual Controller Controller { get; set; } public virtual NetowkDevice NetowkDevice { get; set; } } public class NetowkDevice { [Key] public int Id { get; set; } public string Name { get; set; } } public enum DeviceStatus { Active, Tampered, Ignored }
是否可以基于
ControllerDevice
DeviceStatus
自动填充ActiveDevices
,ActiveDevices
和IngoredDevices
列表,或者我是否必须为每个列表创建三个不同的表。 IEActiveControllerDevice
,IgnoredControllerDevices
和IgnoredControllerDevices
。如果您需要进一步说明,请与我们联系。
Is it possible to have a foreign key mapping based on a specific column value.
I have the following entities.
public class Controller { [Key] public int Id { get; set; } public string Name { get; set; } public virtual List<ControllerDevice> ActiveDevices { get; set; } public virtual List<ControllerDevice> TamperedDevices { get; set; } public virtual List<ControllerDevice> IgnoredDevices { get; set; } } public class ControllerDevice { public int Id { get; set; } public DeviceStatus Status { get; set; } public int ControllerId { get; set; } public int NetworkDeviceId { get; set; } public virtual Controller Controller { get; set; } public virtual NetowkDevice NetowkDevice { get; set; } } public class NetowkDevice { [Key] public int Id { get; set; } public string Name { get; set; } } public enum DeviceStatus { Active, Tampered, Ignored }
Is it possible to have the
ActiveDevices
,TamperedDevices
andIngoredDevices
list be auto populated based onControllerDevice
DeviceStatus
, or would I have to create three different tables for each list. IEActiveControllerDevice
,TamperedControllerDevices
andIgnoredControllerDevices
.Please let me know if you require further explanation.
原文:https://stackoverflow.com/questions/14274185
最满意答案
尝试使用
rbenv shell 2.1.1
为当前shell设置环境adding these two lines inside my bashrc file solved my problem.
export PATH="$HOME/.rbenv/bin:$PATH" eval "$(rbenv init -)"
相关问答
更多-
您的家庭文件夹只能由您而不是其他人写。 宝石抱怨的原因是您的PATH中有您的(不安全的)主文件夹中的文件夹,这意味着任何想要通过重命名/移动.rvm文件夹并用冒名顶替替换的人都可以攻击你。 要修复您的主文件夹,请运行chmod go-w /Users/kristoffer 。 如果在路径中有任何其他不安全的文件夹,您应该同样修复它们。 BTW,磁盘实用程序没有修复的原因是它只修复作为操作系统一部分安装的文件(请参阅Apple的知识库文章 )。 如果从安装DVD引导并从“实用程序”菜单运行密码重置,则可以修复 ...
-
Dir.chdir(dest) do # code that shall be executed while in the dest directory end 使用块调用Dir.chdir将更改为给定目录,执行块然后更改回来。 您也可以在没有块的情况下使用它,在这种情况下它永远不会改变。 Dir.chdir(dest) do # code that shall be executed while in the dest directory end Dir.chdir when invoked ...
-
尝试使用rbenv shell 2.1.1为当前shell设置环境 adding these two lines inside my bashrc file solved my problem. export PATH="$HOME/.rbenv/bin:$PATH" eval "$(rbenv init -)"
-
大约2个月前我刚开始使用rails,在此之前,我主要使用Visual Studio做了asp.net。 像你一样,rails几乎是我第一次看unix命令。 我进入了极限,并决定使用VIM作为我的编辑器,而不是依靠IDE(RadRails,Aptana等)。 如果你走的路线相同,你会有更陡峭的学习曲线! 如果你使用IDE,它可能会容易得多,但几乎没有什么有趣或有趣的IMHO :) 如果你走相同的路线,我需要了解vim,它有很多插件,比如rails.vim,fuzzyfinder,snippets,NERDTr ...
-
你可以使用Kernel#system或Kernel#exec或引用``: $> irb => `git status` => "# On branch develop\nnothing to commit, working directory clean\n" => system('git version') => git version 1.8.3.4 (Apple Git-47) => exec('git version') => git version 1.8.3.4 (A ...
-
与进程相关的Shell命令的Ruby执行无限期地挂起(Ruby Execution of Process-Related Shell Commands Hangs Indefinitely)[2023-04-02]
Whelp,受影响的机器的一个简单的重新启动固定这一个。 去搞清楚。 Whelp, a simple reboot of the impacted machine fixed this one. Go figure. -
在Ruby,OSX和Windows上运行任意系统命令(running arbitrary system commands from Ruby, on OSX and Windows)[2023-01-19]
尝试 system "open -a textmate /Users/apple/Documents/thekbase-temp-files/test5.txt" Try system "open -a textmate /Users/apple/Documents/thekbase-temp-files/test5.txt" -
为了将两个命令传递给shell,您应该运行两次系统命令(请查看本文中的方法8 ) require 'shell' sh = Shell.new IO.foreach("shortURLs.txt") { |x| sh.system("curl -I #{x}") | sh.system("perl -n -e '/^Location: (.*)$/ && print \"$1\n\" ' ") >> "finalURLs.txt" } In order to pass two commands to ...
-
您的错误消息是全部说明: NoMethodError: undefined method `value' for nil:NilClass 你试图在某个时刻调用nil的值。 而且,这可能发生在这里: # Specify request parameters params = { auth_token: auth_token, anchor: Anchor.first.value, # this is the line that's creating problem source:"CRAIG" ...
-
RailsInstaller现在支持Rails 3.1,但对以前的RC版本没有任何承诺。 就像@Fabio所说,尝试更新到最新的Rails版本(在你的Gemfile中更改它)。 此外,如果您已经安装了ruby版本,请确保通过检查系统环境路径变量来使用RailsInstaller版本。 Ruby的唯一途径应该是: C:\RailsInstaller\Ruby1.9.2\bin; needed to run the following and It resolved the problem:- gem ins ...