问:
Where is NEDB file stored?
```<code>var Datastore = require('nedb')
  , db = new Datastore({ filename: 'testdb.db', autoload: true });\
var doc = { hello: 'world'
               , n: 5
               , today: new Date()
               , nedbIsAwesome: true
               , notthere: null
               , notToBeSaved: undefined  // Will not be saved
               , fruits: [ 'apple', 'orange', 'pear' ]
               , infos: { name: 'nedb' }
               };

db.insert(doc, function (err, newDoc) {
    console.log(newDoc);
});
</code>```

I can't find "testdb.db" anywhere in my computer, but the console log show the data exist!
Any suggestion?

答: Finally i know, im using webpack dev server, the file actually there, but only in memory, not written to my harddisk.</p>

Title: Where is NEDB file stored?

Body:
var Datastore = require('nedb')
  , db = new Datastore({ filename: 'testdb.db', autoload: true });\
var doc = { hello: 'world'
               , n: 5
               , today: new Date()
               , nedbIsAwesome: true
               , notthere: null
               , notToBeSaved: undefined  // Will not be saved
               , fruits: [ 'apple', 'orange', 'pear' ]
               , infos: { name: 'nedb' }
               };

db.insert(doc, function (err, newDoc) {
    console.log(newDoc);
});

I can't find "testdb.db" anywhere in my computer, but the console log show the data exist!
Any suggestion?


来源: stackexchange

问:
Count total records in File and compare with trailer records
The contents of the file are as below

```<code>101,abc,2017-03-15,Linux
222,xyz,2016-10-10,Unix
987,def,2017-01-03,Solaris
567,tek,2014-01-09,windows
Trailer|20170331|4
</code>```

I need to compare actual record line which is 4, is equal to total records on trailer(4).

答:
I've made a couple of assumptions:

There will only ever be the records you want to count and a single trailer record.  That is, no other types of data records, no headers, no extra trailer or subtotal records.

On the trailer record, the record count will always be the third field and the delimiter will always be a pipe ("|").

You didn't specify what specific OS or shell you're using, so you might need to tweak some of the commands due to minor differences.

Anyway, here's what I came up with:

```<code>recchk()
{
  #Here's the file we're working with:
  myfile=testfile.txt

  #Let's figure out how many records are in it
  recs=`wc -l $myfile | cut -f1 -d" "`

  #Now subtract 1 because we don't want to count the trailer
  let recs=`expr $recs - 1`

  echo "There are $recs data records in the file."

  #Now we'll find the trailer record and get the third field
  trcnt=`tail -1 $myfile | cut -f3 -d"|"`

  echo "Trailer says there are $trcnt records."

  #Now we'll check to make sure all is well.
  if [ $recs -ne $trcnt ]; then
     echo "Uh-oh!  They don't match\!"
  else
     echo "Right on, daddy-o\!  We're righteous\!"
  fi
}
</code>```

Hope this helps!

ContentLicense: CC BY-SA 3.0

Body:
The contents of the file are as below

101,abc,2017-03-15,Linux
222,xyz,2016-10-10,Unix
987,def,2017-01-03,Solaris
567,tek,2014-01-09,windows
Trailer|20170331|4

I need to compare actual record line which is 4, is equal to total records on trailer(4).

Body:
I've made a couple of assumptions:

There will only ever be the records you want to count and a single trailer record.  That is, no other types of data records, no headers, no extra trailer or subtotal records.

On the trailer record, the record count will always be the third field and the delimiter will always be a pipe ("|").

You didn't specify what specific OS or shell you're using, so you might need to tweak some of the commands due to minor differences.

Anyway, here's what I came up with:

recchk()
{
  #Here's the file we're working with:
  myfile=testfile.txt

  #Let's figure out how many records are in it
  recs=`wc -l $myfile | cut -f1 -d" "`

  #Now subtract 1 because we don't want to count the trailer
  let recs=`expr $recs - 1`

  echo "There are $recs data records in the file."

  #Now we'll find the trailer record and get the third field
  trcnt=`tail -1 $myfile | cut -f3 -d"|"`

  echo "Trailer says there are $trcnt records."

  #Now we'll check to make sure all is well.
  if [ $recs -ne $trcnt ]; then
     echo "Uh-oh!  They don't match\!"
  else
     echo "Right on, daddy-o\!  We're righteous\!"
  fi
}

Hope this helps!


问:
tfs nuget step fails to get an older version of package
During the running of a TFS NuGet Installer build step, I get the below error reported. I have replaced the package name with "some package" in this example as I don't think this is relevant, however it is the only package that yields a failure

```<code>##[error]Unable to find version '2.2.1' of package '<some package>'.
##[error]Unexpected exit code 1 returned from tool NuGet.exe
</code>```

The package I am trying to include exists on my nuget server (ProGet) and the version I need is not the latest version. When working in VS2017 the package is restored as expected so the issue only occurs when TFS runs its build.

答:
I had an issue relating to the nuget Installer Build Steps.

The version that your build is including may not be compatible with the version of the package library.

To fix this I found the location of the nuget.exe under the TFS build agent tools:

C:\Program Files\Microsoft Team Foundation Server 14.0\Build\Agent\Worker\Tools\NuGet.exe

Add this to the Advanced part of the nuget installer build step.

Body:
During the running of a TFS NuGet Installer build step, I get the below error reported. I have replaced the package name with "some package" in this example as I don't think this is relevant, however it is the only package that yields a failure

##[error]Unable to find version '2.2.1' of package '<some package>'.
##[error]Unexpected exit code 1 returned from tool NuGet.exe

The package I am trying to include exists on my nuget server (ProGet) and the version I need is not the latest version. When working in VS2017 the package is restored as expected so the issue only occurs when TFS runs its build.


问:
Rails undefined method "to_time_preserves_timezone"
Something was broken and now no one generator is not works but i'm nothing change after i'm using rails generator last time. That's i got in a console

```<code>/home/sanua/ct/config/initializers/new_framework_defaults.rb:15:in `<top (required)>': undefined method `to_time_preserves_timezone=' for ActiveSupport:Module (NoMethodError)
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:268:in `load'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:268:in `block in load'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:240:in `load_dependency'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:268:in `load'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:652:in `block in load_config_initializer'
 from /usr/lib/ruby/vendor_ruby/active_support/notifications.rb:166:in `instrument'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:651:in `load_config_initializer'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:615:in `each'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:615:in `block in <class:Engine>'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:30:in `instance_exec'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:30:in `run'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:55:in `block in run_initializers'
 from /usr/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
 from /usr/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
 from /usr/lib/ruby/2.3.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
 from /usr/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
 from /usr/lib/ruby/2.3.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:44:in `each'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:44:in `tsort_each_child'
 from /usr/lib/ruby/2.3.0/tsort.rb:415:in `call'
 from /usr/lib/ruby/2.3.0/tsort.rb:415:in `each_strongly_connected_component_from'
 from /usr/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
 from /usr/lib/ruby/2.3.0/tsort.rb:347:in `each'
 from /usr/lib/ruby/2.3.0/tsort.rb:347:in `call'
 from /usr/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
 from /usr/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
 from /usr/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:54:in `run_initializers'
 from /usr/lib/ruby/vendor_ruby/rails/application.rb:352:in `initialize!'
 from /home/sanua/ct/config/environment.rb:5:in `<top (required)>'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:274:in `require'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:274:in `block in require'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:240:in `load_dependency'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:274:in `require'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:92:in `preload'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:143:in `serve'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:131:in `block in run'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:125:in `loop'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:125:in `run'
 from /usr/lib/ruby/vendor_ruby/spring/application/boot.rb:18:in `<top (required)>'
 from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from -e:1:in `<main>'/home/sanua/ct/config/initializers/new_framework_defaults.rb:15:in `<top (required)>': undefined method `to_time_preserves_timezone=' for ActiveSupport:Module (NoMethodError)
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:268:in `load'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:268:in `block in load'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:240:in `load_dependency'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:268:in `load'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:652:in `block in load_config_initializer'
 from /usr/lib/ruby/vendor_ruby/active_support/notifications.rb:166:in `instrument'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:651:in `load_config_initializer'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:615:in `each'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:615:in `block in <class:Engine>'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:30:in `instance_exec'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:30:in `run'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:55:in `block in run_initializers'
 from /usr/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
 from /usr/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
 from /usr/lib/ruby/2.3.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
 from /usr/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
 from /usr/lib/ruby/2.3.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:44:in `each'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:44:in `tsort_each_child'
 from /usr/lib/ruby/2.3.0/tsort.rb:415:in `call'
 from /usr/lib/ruby/2.3.0/tsort.rb:415:in `each_strongly_connected_component_from'
 from /usr/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
 from /usr/lib/ruby/2.3.0/tsort.rb:347:in `each'
 from /usr/lib/ruby/2.3.0/tsort.rb:347:in `call'
 from /usr/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
 from /usr/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
 from /usr/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:54:in `run_initializers'
 from /usr/lib/ruby/vendor_ruby/rails/application.rb:352:in `initialize!'
 from /home/sanua/ct/config/environment.rb:5:in `<top (required)>'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:274:in `require'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:274:in `block in require'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:240:in `load_dependency'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:274:in `require'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:92:in `preload'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:143:in `serve'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:131:in `block in run'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:125:in `loop'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:125:in `run'
 from /usr/lib/ruby/vendor_ruby/spring/application/boot.rb:18:in `<top (required)>'
 from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from -e:1:in `<main>'
</code>```

I constantly see this message whatever i write(rails generate controller, model...)

答: Perhaps you just have an incompatible version of active_support. If you do not belong on gem versions, simply delete Gemfile.lock and execute bundle to update gems and regenerate the Gemfile.lock. If you do, or problem still exists, look through Gemfile and make sure that all rails' gems have the same version specified.

Body:
Something was broken and now no one generator is not works but i'm nothing change after i'm using rails generator last time. That's i got in a console

/home/sanua/ct/config/initializers/new_framework_defaults.rb:15:in `<top (required)>': undefined method `to_time_preserves_timezone=' for ActiveSupport:Module (NoMethodError)
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:268:in `load'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:268:in `block in load'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:240:in `load_dependency'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:268:in `load'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:652:in `block in load_config_initializer'
 from /usr/lib/ruby/vendor_ruby/active_support/notifications.rb:166:in `instrument'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:651:in `load_config_initializer'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:615:in `each'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:615:in `block in <class:Engine>'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:30:in `instance_exec'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:30:in `run'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:55:in `block in run_initializers'
 from /usr/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
 from /usr/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
 from /usr/lib/ruby/2.3.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
 from /usr/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
 from /usr/lib/ruby/2.3.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:44:in `each'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:44:in `tsort_each_child'
 from /usr/lib/ruby/2.3.0/tsort.rb:415:in `call'
 from /usr/lib/ruby/2.3.0/tsort.rb:415:in `each_strongly_connected_component_from'
 from /usr/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
 from /usr/lib/ruby/2.3.0/tsort.rb:347:in `each'
 from /usr/lib/ruby/2.3.0/tsort.rb:347:in `call'
 from /usr/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
 from /usr/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
 from /usr/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:54:in `run_initializers'
 from /usr/lib/ruby/vendor_ruby/rails/application.rb:352:in `initialize!'
 from /home/sanua/ct/config/environment.rb:5:in `<top (required)>'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:274:in `require'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:274:in `block in require'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:240:in `load_dependency'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:274:in `require'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:92:in `preload'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:143:in `serve'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:131:in `block in run'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:125:in `loop'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:125:in `run'
 from /usr/lib/ruby/vendor_ruby/spring/application/boot.rb:18:in `<top (required)>'
 from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from -e:1:in `<main>'/home/sanua/ct/config/initializers/new_framework_defaults.rb:15:in `<top (required)>': undefined method `to_time_preserves_timezone=' for ActiveSupport:Module (NoMethodError)
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:268:in `load'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:268:in `block in load'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:240:in `load_dependency'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:268:in `load'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:652:in `block in load_config_initializer'
 from /usr/lib/ruby/vendor_ruby/active_support/notifications.rb:166:in `instrument'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:651:in `load_config_initializer'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:615:in `each'
 from /usr/lib/ruby/vendor_ruby/rails/engine.rb:615:in `block in <class:Engine>'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:30:in `instance_exec'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:30:in `run'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:55:in `block in run_initializers'
 from /usr/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
 from /usr/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
 from /usr/lib/ruby/2.3.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
 from /usr/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
 from /usr/lib/ruby/2.3.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:44:in `each'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:44:in `tsort_each_child'
 from /usr/lib/ruby/2.3.0/tsort.rb:415:in `call'
 from /usr/lib/ruby/2.3.0/tsort.rb:415:in `each_strongly_connected_component_from'
 from /usr/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
 from /usr/lib/ruby/2.3.0/tsort.rb:347:in `each'
 from /usr/lib/ruby/2.3.0/tsort.rb:347:in `call'
 from /usr/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
 from /usr/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
 from /usr/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
 from /usr/lib/ruby/vendor_ruby/rails/initializable.rb:54:in `run_initializers'
 from /usr/lib/ruby/vendor_ruby/rails/application.rb:352:in `initialize!'
 from /home/sanua/ct/config/environment.rb:5:in `<top (required)>'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:274:in `require'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:274:in `block in require'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:240:in `load_dependency'
 from /usr/lib/ruby/vendor_ruby/active_support/dependencies.rb:274:in `require'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:92:in `preload'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:143:in `serve'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:131:in `block in run'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:125:in `loop'
 from /usr/lib/ruby/vendor_ruby/spring/application.rb:125:in `run'
 from /usr/lib/ruby/vendor_ruby/spring/application/boot.rb:18:in `<top (required)>'
 from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from -e:1:in `'

I constantly see this message whatever i write(rails generate controller, model...)


问:
Why doesn't my query work for a specific parameter?
I have 3 tables

SystemUsers

Complaints

Mappings

1 is used to register website users.
2 is for saving complaints

I will discuss 3 later.

When a complaint is received, it is assigned to a system user i.e. AssignToUser_ID in complaints table.

Complaints:

CompaintID

Date

AssignToUser_ID

Now if a user wants to view complaints then only those complaints should be shown which were assigned to a him not other and that is the part I have solved but....

Now I will discuss MAPPING table.

Mapping:

MappingID

SystemUser_ID

AssignToUser_ID

This table is used to store nominated systemusers i.e. if a complained was assigned to me and I decide to assign it to another user too so he also can view the complaints that were actually assigned to me then it would be possible.
Now this part I have solved somehow but the problem is that If I login as a nominated user then I can view the complaints that were assigned to actual user but if I login as an original user then I can not view the assigned complaints.

My try:

```<code>CREATE Procedure [dbo].[usp_getAllMarkedComplaints]
(

    @SystemUser_ID int

)
AS
Begin

if exists (Select * from mapping where systemuser_id = @SystemUser_ID )
begin
        Select  * From dbo.Complaints Comp
        Where (Comp.AssignToUser_ID IN (select assigntouser_id from mapping where systemuser_id = @SystemUser_ID))      AND
        Comp.ComplaintStatus_ID <3
    end
    else
    begin

        Select * From dbo.Complaints Comp
        Where (Comp.AssignToUser_ID = @SystemUser_ID) AND
        Comp.ComplaintStatus_ID <3

    end
End
</code>```

答:
You use @SystemUser_ID as a systemuser_id AND as a AssignToUser_ID. I think that they are two different notions with their own increments system.
Your AssignToUser_ID n°1 is probably not the same as your systemuser_id n°1.

You need to make two different entries depending on your user type (assigned OR system).

One way to go:

```<code>CREATE Procedure [dbo].[usp_getAllMarkedComplaints]
(
    @user_ID int,
    @user_type char(3)
)
AS
Begin

    if @user_type = 'SYS'
    begin
        Select  * From dbo.Complaints Comp
        Where Comp.AssignToUser_ID IN (select assigntouser_id
                                        from mapping
                                        where systemuser_id = @user_ID)
         AND  Comp.ComplaintStatus_ID <3
    end

    if @user_type = 'ASG'
    begin

        Select * From dbo.Complaints Comp
        Where Comp.AssignToUser_ID = @user_ID
          AND Comp.ComplaintStatus_ID <3

    end
End
</code>```

Another way to go would be to make two different stored procedure.

Body:
I have 3 tables

SystemUsers

Complaints

Mappings

1 is used to register website users.
2 is for saving complaints

I will discuss 3 later.

When a complaint is received, it is assigned to a system user i.e. AssignToUser_ID in complaints table.

Complaints:

CompaintID

Date

AssignToUser_ID

Now if a user wants to view complaints then only those complaints should be shown which were assigned to a him not other and that is the part I have solved but....

Now I will discuss MAPPING table.

Mapping:

MappingID

SystemUser_ID

AssignToUser_ID

This table is used to store nominated systemusers i.e. if a complained was assigned to me and I decide to assign it to another user too so he also can view the complaints that were actually assigned to me then it would be possible.
Now this part I have solved somehow but the problem is that If I login as a nominated user then I can view the complaints that were assigned to actual user but if I login as an original user then I can not view the assigned complaints.

My try:

CREATE Procedure [dbo].[usp_getAllMarkedComplaints]
(

    @SystemUser_ID int

)
AS
Begin

if exists (Select * from mapping where systemuser_id = @SystemUser_ID )
begin
        Select  * From dbo.Complaints Comp
        Where (Comp.AssignToUser_ID IN (select assigntouser_id from mapping where systemuser_id = @SystemUser_ID))      AND
        Comp.ComplaintStatus_ID <3
    end
    else
    begin

        Select * From dbo.Complaints Comp
        Where (Comp.AssignToUser_ID = @SystemUser_ID) AND
        Comp.ComplaintStatus_ID <3

    end
End

Body:
You use @SystemUser_ID as a systemuser_id AND as a AssignToUser_ID. I think that they are two different notions with their own increments system.
Your AssignToUser_ID n°1 is probably not the same as your systemuser_id n°1.

You need to make two different entries depending on your user type (assigned OR system).

One way to go:

CREATE Procedure [dbo].[usp_getAllMarkedComplaints]
(
    @user_ID int,
    @user_type char(3)
)
AS
Begin

    if @user_type = 'SYS'
    begin
        Select  * From dbo.Complaints Comp
        Where Comp.AssignToUser_ID IN (select assigntouser_id
                                        from mapping
                                        where systemuser_id = @user_ID)
         AND  Comp.ComplaintStatus_ID <3
    end

    if @user_type = 'ASG'
    begin

        Select * From dbo.Complaints Comp
        Where Comp.AssignToUser_ID = @user_ID
          AND Comp.ComplaintStatus_ID <3

    end
End

Another way to go would be to make two different stored procedure.


问:
How to get two <div> floating below each other
I want to ask how can I move floated  below another so both of them are floating on the same side but they're below each other. Thanks.</p>

答:
Simply try to insert a
 tag between both div. This should work.

ContentLicense: CC BY-SA 4.0

Body: Simply try to insert a <br> tag between both div. This should work.


问:
PHP - Remove Line Breaks From Textarea
I was wondering what I am missing in my code.  I have a large form that is pushing all values to a .csv file.  There are instances of textareas and every time I put some text content in and add a line break (hit the enter-key) within the .csv document, any line of text after the first breaks the flow of the values within the .csv, and starts a new line.

I've tried checking taking the value via php and removing any spaces or breaks, but it doesn't seem to be working.

Can anyone tell me what I am missing?

HTML:

```<code><textarea id="fianlCommentsText" name="fianlCommentsText"></textarea>
</code>```

PHP:

```<code>$finalCommentsText = $_POST["finalCommentsText"];
function finalCommentsLineCheck()
    {
        global $finalCommentsText;
        preg_replace( "/\r|\n/", "", $finalCommentsText );
    }
    finalCommentsLineCheck();
</code>```

答:
In my case I solved in this way:

Output to a textarea removing the '\n' characters:

```<code><!-- this textarea will show blank carriage return and not \n characters -->
<textarea  class="settinginput" id="message" name="message">
<?php echo str_replace('\n',"\n",$message); ?>
</textarea>
</code>```

After submit here is how to replace the carriage returns with the '\n' not expanded characters:

```<code>str_replace("\r\n",'\n',$_POST['message'])
</code>```

Note that the replace function uses double quotes and single quotes in order to save the string with no expansion for escape sequences.

Title: PHP - Remove Line Breaks From Textarea

Body:
I was wondering what I am missing in my code.  I have a large form that is pushing all values to a .csv file.  There are instances of textareas and every time I put some text content in and add a line break (hit the enter-key) within the .csv document, any line of text after the first breaks the flow of the values within the .csv, and starts a new line.

I've tried checking taking the value via php and removing any spaces or breaks, but it doesn't seem to be working.

Can anyone tell me what I am missing?

HTML:

<textarea id="fianlCommentsText" name="fianlCommentsText"></textarea>

PHP:

$finalCommentsText = $_POST["finalCommentsText"];
function finalCommentsLineCheck()
    {
        global $finalCommentsText;
        preg_replace( "/\r|\n/", "", $finalCommentsText );
    }
    finalCommentsLineCheck();

Body:
In my case I solved in this way:

Output to a textarea removing the '\n' characters:

<!-- this textarea will show blank carriage return and not \n characters -->
<textarea  class="settinginput" id="message" name="message">
<?php echo str_replace('\n',"\n",$message); ?>
</textarea>

After submit here is how to replace the carriage returns with the '\n' not expanded characters:

str_replace("\r\n",'\n',$_POST['message'])

Note that the replace function uses double quotes and single quotes in order to save the string with no expansion for escape sequences.


问:
Can't launch MySQL Workbench v6.3.8
I've seen similar posts regarding this issue on the site, but none of the posted resolutions worked for me.  When I attempt to launch MySQL Workbench, nothing happens on-screen & 2 application log errors are generated. One is a very generic KERNEL32 event, and the other is .NET related:

Application: MySQLWorkbench.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.IO.FileNotFoundException Stack: at MySQL.GUI.Workbench.Program.Main(System.String[])

Most of the resolutions I've found online relate to missing prerequisites, which include

.NET Framework 4.5

Visual C++ Redistributable for Visual Studio 2015

I have installed both of these on the machine but am still seeing the same behavior.  Can anyone suggest anything else to try?

答: Upgrading to MySQL Workbench 6.3.9 resolved the issue</p>

Title: Can't launch MySQL Workbench v6.3.8


问:
set page orientation using header
Given a php file, I export its output to an .odt file (OpenOffice Writer) by means of the following lines:

```<code>header('Content-Type: application/vnd.oasis.opendocument.text');
header('Content-Disposition: attachment; filename="myfile.odt"');
</code>```

I can't figure out how to set the page orientation to landscape. By default, it is set to portrait.

Any hints?

答:
I've found a solution using CSS:

```<code>@page {
  size: landscape;
}
</code>```

It seems to be working, at least on Firefox.
The answer was here:
Landscape printing from HTML

Title: set page orientation using header

Body:
Given a php file, I export its output to an .odt file (OpenOffice Writer) by means of the following lines:

header('Content-Type: application/vnd.oasis.opendocument.text');
header('Content-Disposition: attachment; filename="myfile.odt"');

I can't figure out how to set the page orientation to landscape. By default, it is set to portrait.

Any hints?

Body:
I've found a solution using CSS:

@page {
  size: landscape;
}

It seems to be working, at least on Firefox.
The answer was here:
Landscape printing from HTML


问:
Rolling back changes with reset and force push
i have seen similar topics here, but i didn't find the clear answer.

i have commited and pushed few changes on a remote branch, but that was a mistake and would like to reset this branch to the state it was couple of days ago. (using source tree btw)

```<code>- bad pushed commit
- bad pushed commit
- bad pushed commit
- place i want to return to
- older commits
</code>```

if i do a hard reset to the place i want to return to and then force push it. Will that do the trick, are there any issues with that ?

答:
This will fix it, but you have to be wary about changes made on top of these bad commits by other collaborators.</p>

```<code>git reset HEAD~3 --hard
git push -f origin <branch-name>
</code>```

Body:
i have seen similar topics here, but i didn't find the clear answer.

i have commited and pushed few changes on a remote branch, but that was a mistake and would like to reset this branch to the state it was couple of days ago. (using source tree btw)

- bad pushed commit
- bad pushed commit
- bad pushed commit
- place i want to return to
- older commits

if i do a hard reset to the place i want to return to and then force push it. Will that do the trick, are there any issues with that ?

Body:
This will fix it, but you have to be wary about changes made on top of these bad commits by other collaborators.

git reset HEAD~3 --hard
git push -f origin <branch-name>


答:
You can use clear: both;.

.right {
  float: right;
  clear:both;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="right">test1</div>
<div class="right">test1</div></code>```

Title: How to get two <div> floating below each other

Body: I want to ask how can I move floated  below another so both of them are floating on the same side but they're below each other. Thanks.

Body:
You can use clear: both;.

.right {
  float: right;
  clear:both;
}

<div class="right">test1</div>
<div class="right">test1</div>


问:
Node Express - multer causing controller call failure and vice versa
Routes.js

The below code worked.

```<code>var upload= multer({ storage: storage})
app.post('/upload', [ upload.any(), function(req, res) {
     console.log(req.body) // form fields
     console.log(req.files) // form files
     res.status(204).end()
   }]);
</code>```

However, I wanted to call a controller method as well which is located in my file uploadController.js

So I did this, down below.

```<code> app.post('/upload', controllers.uploadFiles.upload, [ upload.any(), function(req, res) {
                    console.log(req.body) // form fields
                    console.log(req.files) // form files
                    res.status(204).end()
                }]);
</code>```

However, what happened was that my controller was called but then uploading part failed, i.e the below part wasn't called.

```<code>console.log(req.body) // form fields
 console.log(req.files) // form files
 res.status(204).end()
</code>```

In conclusion, either one of them (multer or controller) work, both of them don't.
   What could be wrong with this?

UPDATE

Tried the below. Only controller gets called. No file uploading done.

```<code>  app.post('/upload', controllers.dataUpload.upload, [ upload.any(), function(req, res, next) {
                    console.log(req.body) // form fields
                    console.log(req.files) // form files
                    next()
                }]);
</code>```

答:
You haven't called next from the first controller. The execution ends after you call res.end(). If you want the execution to continue to the next route match, you must call next() on the first middle-ware.

You can read more about routing and middlewares in the guide: https://expressjs.com/en/guide/routing.html

Here are some quotes that might be relevant:

You need to call the next function so that the next controller is called:

More than one callback function can handle a route (make sure you specify the next object).

When you call methods on the res object, the execution is terminated and the next controller is ignored:

The methods on the response object (res) in the following table can send a response to the client, and terminate the request-response cycle. If none of these methods are called from a route handler, the client request will be left hanging.

Body:
Routes.js

The below code worked.

var upload= multer({ storage: storage})
app.post('/upload', [ upload.any(), function(req, res) {
     console.log(req.body) // form fields
     console.log(req.files) // form files
     res.status(204).end()
   }]);

However, I wanted to call a controller method as well which is located in my file uploadController.js

So I did this, down below.

 app.post('/upload', controllers.uploadFiles.upload, [ upload.any(), function(req, res) {
                    console.log(req.body) // form fields
                    console.log(req.files) // form files
                    res.status(204).end()
                }]);

However, what happened was that my controller was called but then uploading part failed, i.e the below part wasn't called.

console.log(req.body) // form fields
 console.log(req.files) // form files
 res.status(204).end()

In conclusion, either one of them (multer or controller) work, both of them don't.
   What could be wrong with this?

UPDATE

Tried the below. Only controller gets called. No file uploading done.

  app.post('/upload', controllers.dataUpload.upload, [ upload.any(), function(req, res, next) {
                    console.log(req.body) // form fields
                    console.log(req.files) // form files
                    next()
                }]);


问:
Batch - Trouble with Redirect within For Loop
I'm having difficulty getting a command to run in a For Loop.  From a cmd prompt this works fine:

```<code>"C:\Program Files (x86)\MakeMKV\makemkvcon64.exe" -r info | find "E:"
</code>```

But, the following seems to have a syntax problem

```<code>for /f "tokens=1-7 delims=," %%A in ('"C:\Program Files (x86)\MakeMKV\makemkvcon64.exe" ^-r info ^| find "E:"') do (set _DRVID=%%A)
</code>```

Yielding an error - C:\Program' is not recognized as an internal or external command, operable program or batch file.

Just for reference, I found a way to get my desired result with the following:
I can get the following code to work in Batch as well generating the desired output:

```<code>for /f "tokens=1-7 delims=," %%A in ('"C:\Program Files (x86)\MakeMKV\makemkvcon64.exe" ^-r info') do (IF %%G=="E:" set _DRVID=%%A)
</code>```

What am I doing wrong?

答:
Hmm - after a little experimentation, I got this (or my version) to work:

```<code>for /f "delims=" %%X in ('"C:\Program Files (x86)\MakeMKV\makemkvcon64.exe" ^-r') do (
 for /f "tokens=1-7 delims=," %%A in ('ECHO(%%X^| find "E:"') do (set _DRVID=%%A)
)
</code>```

But I've not been able to get the output of a quoted-executablename to be filtered as expected by the find.

Body:
I'm having difficulty getting a command to run in a For Loop.  From a cmd prompt this works fine:

"C:\Program Files (x86)\MakeMKV\makemkvcon64.exe" -r info | find "E:"

But, the following seems to have a syntax problem

for /f "tokens=1-7 delims=," %%A in ('"C:\Program Files (x86)\MakeMKV\makemkvcon64.exe" ^-r info ^| find "E:"') do (set _DRVID=%%A)

Yielding an error - C:\Program' is not recognized as an internal or external command, operable program or batch file.

Just for reference, I found a way to get my desired result with the following:
I can get the following code to work in Batch as well generating the desired output:

for /f "tokens=1-7 delims=," %%A in ('"C:\Program Files (x86)\MakeMKV\makemkvcon64.exe" ^-r info') do (IF %%G=="E:" set _DRVID=%%A)

What am I doing wrong?

Body:
Hmm - after a little experimentation, I got this (or my version) to work:

for /f "delims=" %%X in ('"C:\Program Files (x86)\MakeMKV\makemkvcon64.exe" ^-r') do (
 for /f "tokens=1-7 delims=," %%A in ('ECHO(%%X^| find "E:"') do (set _DRVID=%%A)
)

But I've not been able to get the output of a quoted-executablename to be filtered as expected by the find.


问:
Database-First & Error: Unable to determine a valid ordering for dependent operations
I have a problem with the project I am working on. On POST:Edit, it saves my changes. On POST:Create, I receive this error: "Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values."

So I did what my teachers taught us in College: I just Googled it. The answers however were suggesting to change the ModelBuilder-fluent API. I do not think this would be inappropriate since I use Database-First approach (It says it is only for Code-First) AND my Save is functional in Edit. Since I wanted to work with ViewModels, I followed this tutorial. I even found and posted a solution for the tutorial about the Create method to help me with my problem. Please help me. I am about to throw my computer out of the window. Which is kind of complicated because they are made of tempered glass.

So here's the metadata for my model (with minimal data annotation for readability sake:

```<code>public partial class Employe
{
    sealed class Metadata
    {
        [Key]
        public int IdEmploye { get; set; }

        public string NomEmploye { get; set; }

        public string PrenomEmploye { get; set; }

        [ForeignKey("TitreEmploye_IdTitre")]
        public int IdTitre { get; set; }

        [ForeignKey("Departement_IdDepartement")]
        public int IdDepartement { get; set; }

        [ForeignKey("Employe_IdSuperviseur")]
        public int IdSuperviseur { get; set; }

        public System.DateTime DateEmbauche { get; set; }

        public Nullable<System.DateTime> DateDepart { get; set; }

        public string StatutEmploye { get; set; }

        [ForeignKey("Employeur_IdEmployeur")]
        public int IdEmployeur { get; set; }

        [ForeignKey("Localisation_IdLocalisation")]
        public int IdLocalisation { get; set; }

        public string Langue { get; set; }

        public Nullable<bool> CarteAcces { get; set; }

        [ForeignKey("TelephoneBureau_IdTelephoneBureau")]
        public Nullable<int> IdTelephoneBureau { get; set; }

        public Nullable<bool> CarteAffaire { get; set; }

        public string AdresseCourriel { get; set; }

        public bool CodeAlarme { get; set; }

        public System.DateTime DateNaissance { get; set; }

        public Nullable<bool> IsSuperviseur { get; set; }

        public Nullable<bool> IsActif { get; set; }
    }
}
</code>```

}

Here's my problematic(?) model:

```<code>public partial class Employe
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public Employe()
    {
        this.AccesApplicatif1 = new HashSet<AccesApplicatif>();
        this.TelephoneCellulaire1 = new HashSet<TelephoneCellulaire>();
        this.CleBatiment1 = new HashSet<CleBatiment>();
        this.EquipementInfo = new HashSet<EquipementInfo>();
        this.GroupeSecurite1 = new HashSet<GroupeSecurite>();
        this.VehiculeCompagnie1 = new HashSet<VehiculeCompagnie>();
        this.Employe1 = new HashSet<Employe>();
    }

    public int IdEmploye { get; set; }
    public string NomEmploye { get; set; }
    public string PrenomEmploye { get; set; }
    public int IdTitre { get; set; }
    public int IdDepartement { get; set; }
    public int IdSuperviseur { get; set; }
    public System.DateTime DateEmbauche { get; set; }
    public Nullable<System.DateTime> DateDepart { get; set; }
    public string StatutEmploye { get; set; }
    public int IdEmployeur { get; set; }
    public int IdLocalisation { get; set; }
    public string Langue { get; set; }
    public Nullable<bool> CarteAcces { get; set; }
    public Nullable<int> IdTelephoneBureau { get; set; }
    public Nullable<bool> CarteAffaire { get; set; }
    public string AdresseCourriel { get; set; }
    public bool CodeAlarme { get; set; }
    public System.DateTime DateNaissance { get; set; }
    public Nullable<bool> IsSuperviseur { get; set; }
    public Nullable<bool> IsActif { get; set; }

    public virtual Departement Departement { get; set; }
    public virtual Employeur Employeur { get; set; }
    public virtual Localisation Localisation { get; set; }
    public virtual TelephoneBureau TelephoneBureau { get; set; }
    public virtual TitreEmploye TitreEmploye { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<AccesApplicatif> AccesApplicatif1 { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<TelephoneCellulaire> TelephoneCellulaire1 { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<CleBatiment> CleBatiment1 { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<EquipementInfo> EquipementInfo { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<GroupeSecurite> GroupeSecurite1 { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<VehiculeCompagnie> VehiculeCompagnie1 { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Employe> Employe1 { get; set; }
    public virtual Employe Employe2 { get; set; }

    public string NomSuperviseur
    {
        get
        {
            return string.Format("{0} {1}", PrenomEmploye, NomEmploye);
        }
    }
}
</code>```

As I said, since I wanted to work with ViewModels, here's the culprit:

```<code>public partial class EmployeVM
{
    public Employe Employe { get; set; } //Employe

    public string NomEmploye { get; set; } //Employe

    public string PrenomEmploye { get; set; } //Employe

    public DateTime DateNaissance { get; set; } //Employe

    public string Langue { get; set; } //Employe

    //////////////////////////////////////////////////////////////
    public IEnumerable<Titre> Titres { get; set; } //TitreEmploye
    public class Titre
    {
        public string description { get; set; } //TitreEmploye
    }

    //////////////////////////////////////////////////////////////
    public IEnumerable<Departement> Departements { get; set; } //Departement
    public class Departement
    {
        public string description { get; set; } //Departement
    }

    //////////////////////////////////////////////////////////////
    public IEnumerable<Superviseur> Superviseurs { get; set; } //Employe
    public class Superviseur
    {
        public string nomSuperviseur { get; set; } //Employe
    }

    public string StatutEmploye { get; set; } //Employe

    public DateTime DateEmbauche { get; set; } //Employe

    public Nullable<System.DateTime> DateDepart { get; set; } //Employe

    //////////////////////////////////////////////////////////////
    public IEnumerable<Employeur> Employeurs { get; set; } //Employeur
    public class Employeur
    {
        public string nomEmployeur { get; set; } //Employeur
    }

    //////////////////////////////////////////////////////////////
    public IEnumerable<Localisation> Localisations { get; set; } //Localisation
    public class Localisation
    {
        public string description { get; set; } //Localisation
    }

    public bool CarteAcces { get; set; } //Employe

    //////////////////////////////////////////////////////////////
    public IEnumerable<TelephoneBureau> TelephoneBureaux { get; set; } //TelephoneBureau
    public class TelephoneBureau
    {
        public string extension { get; set; } //TelephoneBureau
    }

    //////////////////////////////////////////////////////////////
    public IEnumerable<SelectListItem> AllTelephoneCellulaires { get; set; } //TelephoneCellulaire
    private List<int> _selectedTelephoneCellulaires;
    public List<int> SelectedTelephoneCellulaires
    {
        get
        {
            if (_selectedTelephoneCellulaires == null)
            {
                _selectedTelephoneCellulaires = Employe.TelephoneCellulaire1.Select(m => m.IdTelephoneCellulaire).ToList();
            }
            return _selectedTelephoneCellulaires;
        }
        set { _selectedTelephoneCellulaires = value; }
    }

    public bool CarteAffaire { get; set; } //Employe

    //////////////////////////////////////////////////////////////
    public IEnumerable<SelectListItem> AllEquipementInformatiques { get; set; } //EquipementInfo
    private List<int> _selectedEquipementInformatiques;
    public List<int> SelectedEquipementInformatiques
    {
        get
        {
            if (_selectedEquipementInformatiques == null)
            {
                _selectedEquipementInformatiques = Employe.EquipementInfo.Select(m => m.IdEquipementInfo).ToList();
            }
            return _selectedEquipementInformatiques;
        }
        set { _selectedEquipementInformatiques = value; }
    }

    public string AdresseCourriel { get; set; } //Employe

    //////////////////////////////////////////////////////////////
    public IEnumerable<SelectListItem> AllGroupeSecurites { get; set; } //GroupeSecurite
    private List<int> _selectedGroupeSecurites;
    public List<int> SelectedGroupeSecurites
    {
        get
        {
            if (_selectedGroupeSecurites == null)
            {
                _selectedGroupeSecurites = Employe.GroupeSecurite1.Select(m => m.IdGroupeSecurite).ToList();
            }
            return _selectedGroupeSecurites;
        }
        set { _selectedGroupeSecurites = value; }
    }

    //////////////////////////////////////////////////////////////
    public IEnumerable<SelectListItem> AllAccesApplicatifs { get; set; } //AccesApplicatif
    private List<int> _selectedAccesApplicatifs;
    public List<int> SelectedAccesApplicatifs
    {
        get
        {
            if (_selectedAccesApplicatifs == null)
            {
                _selectedAccesApplicatifs = Employe.AccesApplicatif1.Select(m => m.IdAccesApplicatif).ToList();
            }
            return _selectedAccesApplicatifs;
        }
        set { _selectedAccesApplicatifs = value; }
    }

    public bool CodeAlarme { get; set; } //Employe

    //////////////////////////////////////////////////////////////
    public IEnumerable<SelectListItem> AllCleBatiments { get; set; } //CleBatiment
    private List<int> _selectedCleBatiments;
    public List<int> SelectedCleBatiments
    {
        get
        {
            if (_selectedCleBatiments == null)
            {
                _selectedCleBatiments = Employe.CleBatiment1.Select(m => m.IdCleBatiment).ToList();
            }
            return _selectedCleBatiments;
        }
        set { _selectedCleBatiments = value; }
    }

    //////////////////////////////////////////////////////////////
    public IEnumerable<SelectListItem> AllVehiculeCompagnies { get; set; } //VehiculeCompagnie
    private List<int> _selectedVehiculeCompagnies;
    public List<int> SelectedVehiculeCompagnies
    {
        get
        {
            if (_selectedVehiculeCompagnies == null)
            {
                _selectedVehiculeCompagnies = Employe.VehiculeCompagnie1.Select(m => m.IdVehiculeCompagnie).ToList();
            }
            return _selectedVehiculeCompagnies;
        }
        set { _selectedVehiculeCompagnies = value; }
    }

    public bool IsSuperviseur { get; set; } //Employe

    public bool IsActif { get; set; } //Employe

    public EmployeVM()
    {
        AllTelephoneCellulaires = new List<SelectListItem>();
        AllEquipementInformatiques = new List<SelectListItem>();
        AllGroupeSecurites = new List<SelectListItem>();
        AllAccesApplicatifs = new List<SelectListItem>();
        AllCleBatiments = new List<SelectListItem>();
        AllVehiculeCompagnies = new List<SelectListItem>();
    }
}
</code>```

And here's the Create part of my Controller (I KNOW I will have to add some methods to comply to DRY, but for now, that's what it is:

```<code>// GET: Employes/Create
    //[AcceptVerbs(HttpVerbs.Get), ImportModelStateFromTempData]
    public ActionResult Create()
    {
        var employeView = new EmployeVM();

        //Population pour les ListBoxFor
        var allTelephoneCellulaireActifList = db.TelephoneCellulaireActif.ToList();
        ViewBag.AllTelephoneCellulaires = allTelephoneCellulaireActifList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdTelephoneCellulaire.ToString()
        });
        var allEquipementInfoActifList = db.EquipementInfoActif.ToList();
        ViewBag.AllEquipementInformatiques = allEquipementInfoActifList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdEquipementInfo.ToString()
        });
        var allGroupeSecuriteList = db.GroupeSecurite.ToList();
        ViewBag.AllGroupeSecurites = allGroupeSecuriteList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdGroupeSecurite.ToString()
        });
        var allAccesApplicatifActifList = db.AccesApplicatifActif.ToList();
        ViewBag.AllAccesApplicatifs = allAccesApplicatifActifList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdAccesApplicatif.ToString()
        });
        var allCleBatimentList = db.CleBatiment.ToList();
        ViewBag.AllCleBatiments = allCleBatimentList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdCleBatiment.ToString()
        });
        var allVehiculeCompagnieActifList = db.VehiculeCompagnieActif.ToList();
        ViewBag.AllVehiculeCompagnies = allVehiculeCompagnieActifList.Select(o => new SelectListItem
        {
            Text = o.DescriptionVehicule,
            Value = o.IdVehiculeCompagnie.ToString()
        });

        //Zero-or-One-to-Many relationships
        List<TitreEmployeActif> ListeTitreEmployeActif = db.TitreEmployeActif.OrderBy(titre => titre.Description).ToList();
        ViewBag.IdTitre = new SelectList(ListeTitreEmployeActif, "IdTitre", "Description");

        List<Departement> ListeDepartement = db.Departement.OrderBy(departement => departement.Description).ToList();
        ViewBag.IdDepartement = new SelectList(ListeDepartement, "IdDepartement", "Description");

        List<EmployeSuperviseurActif> ListeEmployeSuperviseurActif = db.EmployeSuperviseurActif.OrderBy(sup => sup.PrenomNom).ToList();
        ViewBag.IdSuperviseur = new SelectList(ListeEmployeSuperviseurActif, "IdEmploye", "PrenomNom");

        List<Employeur> ListeEmployeur = db.Employeur.OrderBy(employeur => employeur.NomEmployeur).ToList();
        ViewBag.IdEmployeur = new SelectList(ListeEmployeur, "IdEmployeur", "NomEmployeur");

        List<Localisation> ListeLocalisation = db.Localisation.OrderBy(localisation => localisation.Description).ToList();
        ViewBag.IdLocalisation = new SelectList(ListeLocalisation, "IdLocalisation", "Description");

        List<TelephoneBureauActif> ListeTelephoneBureauActif = db.TelephoneBureauActif.OrderBy(phone => phone.Extension).ToList();
        ViewBag.IdTelephoneBureau = new SelectList(ListeTelephoneBureauActif, "IdTelephoneBureau", "Extension");

        return View();
    }

    // POST: Employes/Create
    // To protect from overposting attacks, please enable the specific properties you want to bind to,
    // for more details see http://go.microsoft.com/fwlink/?LinkId=317598.
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create(EmployeVM employeView)
    {
        if (!ModelState.IsValid)
        {
            foreach (var obj in ModelState.Values)
            {
                foreach (var error in obj.Errors)
                {
                    if (!string.IsNullOrEmpty(error.ErrorMessage))
                        System.Diagnostics.Debug.WriteLine("ERROR WHY = " + error.ErrorMessage);
                }
            }
        }

        if (ModelState.IsValid)
        {
            var employeToAdd = db.Employe
                .Include(e => e.TelephoneCellulaire1)
                .Include(e => e.EquipementInfo)
                .Include(e => e.GroupeSecurite1)
                .Include(e => e.AccesApplicatif1)
                .Include(e => e.CleBatiment1)
                .Include(e => e.VehiculeCompagnie1)
                .First();

            if (TryUpdateModel(employeToAdd, "Employe", new string[] { "IdEmploye", "NomEmploye", "PrenomEmploye", "IdTitre", "IdDepartement", "IdSuperviseur", "DateEmbauche", "DateDepart", "StatutEmploye", "IdEmployeur", "IdLocalisation", "Langue", "CarteAcces", "TelephoneCellulaire", "IdTelephoneBureau", "CarteAffaire", "EquipementInformatique", "AdresseCourriel", "GroupeSecurite", "AccesApplicatif", "CodeAlarme", "CleBatiment", "VehiculeCompagnie", "DateNaissance", "IsSuperviseur", "IsActif" }))
            {
                var updatedTelephoneCellulaires = new HashSet<int>(employeView.SelectedTelephoneCellulaires);
                var updatedEquipementInformatiques = new HashSet<int>(employeView.SelectedEquipementInformatiques);
                var updatedGroupeSecurites = new HashSet<int>(employeView.SelectedGroupeSecurites);
                var updatedAccesApplicatifs = new HashSet<int>(employeView.SelectedAccesApplicatifs);
                var updatedCleBatiments = new HashSet<int>(employeView.SelectedCleBatiments);
                var updatedVehiculeCompagnies = new HashSet<int>(employeView.SelectedVehiculeCompagnies);

                //Prochaine ligne db.TelephoneCellulaire1 !!! ou db.TelephoneCellulaireActif ???  Check readonly
                foreach (TelephoneCellulaire telephone in db.TelephoneCellulaire)
                {
                    if (!updatedTelephoneCellulaires.Contains(telephone.IdTelephoneCellulaire))
                    {
                        employeToAdd.TelephoneCellulaire1.Remove(telephone);
                    }
                    else
                    {
                        employeToAdd.TelephoneCellulaire1.Add(telephone);
                    }
                }
                foreach (EquipementInfo equipement in db.EquipementInfo)
                {
                    if (!updatedEquipementInformatiques.Contains(equipement.IdEquipementInfo))
                    {
                        employeToAdd.EquipementInfo.Remove(equipement);
                    }
                    else
                    {
                        employeToAdd.EquipementInfo.Add(equipement);
                    }
                }
                foreach (GroupeSecurite groupe in db.GroupeSecurite)
                {
                    if (!updatedGroupeSecurites.Contains(groupe.IdGroupeSecurite))
                    {
                        employeToAdd.GroupeSecurite1.Remove(groupe);
                    }
                    else
                    {
                        employeToAdd.GroupeSecurite1.Add(groupe);
                    }
                }
                foreach (AccesApplicatif acces in db.AccesApplicatif)
                {
                    if (!updatedAccesApplicatifs.Contains(acces.IdAccesApplicatif))
                    {
                        employeToAdd.AccesApplicatif1.Remove(acces);
                    }
                    else
                    {
                        employeToAdd.AccesApplicatif1.Add(acces);
                    }
                }
                foreach (CleBatiment cle in db.CleBatiment)
                {
                    if (!updatedCleBatiments.Contains(cle.IdCleBatiment))
                    {
                        employeToAdd.CleBatiment1.Remove(cle);
                    }
                    else
                    {
                        employeToAdd.CleBatiment1.Add(cle);
                    }
                }
                foreach (VehiculeCompagnie vehicule in db.VehiculeCompagnie)
                {
                    if (!updatedVehiculeCompagnies.Contains(vehicule.IdVehiculeCompagnie))
                    {
                        employeToAdd.VehiculeCompagnie1.Remove(vehicule);
                    }
                    else
                    {
                        employeToAdd.VehiculeCompagnie1.Add(vehicule);
                    }
                }
            }
            db.Employe.Add(employeToAdd);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        var allTelephoneCellulaireActifList = db.TelephoneCellulaireActif.ToList();
        ViewBag.AllTelephoneCellulaires = allTelephoneCellulaireActifList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdTelephoneCellulaire.ToString()
        });
        var allEquipementInfoActifList = db.EquipementInfoActif.ToList();
        ViewBag.AllEquipementInformatiques = allEquipementInfoActifList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdEquipementInfo.ToString()
        });
        var allGroupeSecuriteList = db.GroupeSecurite.ToList();
        ViewBag.AllGroupeSecurites = allGroupeSecuriteList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdGroupeSecurite.ToString()
        });
        var allAccesApplicatifActifList = db.AccesApplicatifActif.ToList();
        ViewBag.AllAccesApplicatifs = allAccesApplicatifActifList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdAccesApplicatif.ToString()
        });
        var allCleBatimentList = db.CleBatiment.ToList();
        ViewBag.AllCleBatiments = allCleBatimentList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdCleBatiment.ToString()
        });
        var allVehiculeCompagnieActifList = db.VehiculeCompagnieActif.ToList();
        ViewBag.AllVehiculeCompagnies = allVehiculeCompagnieActifList.Select(o => new SelectListItem
        {
            Text = o.DescriptionVehicule,
            Value = o.IdVehiculeCompagnie.ToString()
        });

        //Zero-or-One-to-Many relationships
        List<TitreEmployeActif> ListeTitreEmployeActif = db.TitreEmployeActif.OrderBy(titre => titre.Description).ToList();
        ViewBag.IdTitre = new SelectList(ListeTitreEmployeActif, "IdTitre", "Description");

        List<Departement> ListeDepartement = db.Departement.OrderBy(departement => departement.Description).ToList();
        ViewBag.IdDepartement = new SelectList(ListeDepartement, "IdDepartement", "Description");

        List<EmployeSuperviseurActif> ListeEmployeSuperviseurActif = db.EmployeSuperviseurActif.OrderBy(sup => sup.PrenomNom).ToList();
        ViewBag.IdSuperviseur = new SelectList(ListeEmployeSuperviseurActif, "IdEmploye", "PrenomNom");

        List<Employeur> ListeEmployeur = db.Employeur.OrderBy(employeur => employeur.NomEmployeur).ToList();
        ViewBag.IdEmployeur = new SelectList(ListeEmployeur, "IdEmployeur", "NomEmployeur");

        List<Localisation> ListeLocalisation = db.Localisation.OrderBy(localisation => localisation.Description).ToList();
        ViewBag.IdLocalisation = new SelectList(ListeLocalisation, "IdLocalisation", "Description");

        List<TelephoneBureauActif> ListeTelephoneBureauActif = db.TelephoneBureauActif.OrderBy(phone => phone.Extension).ToList();
        ViewBag.IdTelephoneBureau = new SelectList(ListeTelephoneBureauActif, "IdTelephoneBureau", "Extension");

        return View(employeView);
    }
</code>```

And just to complete the picture, an extract from Create.cshtml:

```<code>        <div class="form-group">
        @Html.LabelFor(model => model.AllEquipementInformatiques, "Équipements informatiques", htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.ListBoxFor(model => model.SelectedEquipementInformatiques, (IEnumerable<SelectListItem>)ViewBag.AllEquipementInformatiques, new { @class = "form-control" })
        </div>
    </div>
</code>```

Speaking about a picture, here's a little capture of one of my Many-to-Many table, with data entered with Edit:

Employe_VehiculeCompagnie

The thing to know (and I think it might be part of the problem) is: all of the 6 Many-To-Many relationships are optional. But even when I try to create a new Employe with at least one item in each of the 6 Many-to-Many field, it throws that error. And it still works in Edit. Questions: why this error is thrown and how can I make my app works? Any help would be greatly appreciated.

Edit:
Should I add this? One of my join table:

```<code>CREATE TABLE [dbo].[Employe_GroupeSecurite] (
[IdEmploye]        INT NOT NULL,
[IdGroupeSecurite] INT NOT NULL,
PRIMARY KEY CLUSTERED ([IdEmploye] ASC, [IdGroupeSecurite] ASC),
CONSTRAINT [FK_Employe_GroupeSecurite_Employe] FOREIGN KEY ([IdEmploye]) REFERENCES [dbo].[Employe] ([IdEmploye]),
CONSTRAINT [FK_Employe_GroupeSecurite_GroupeSecurite] FOREIGN KEY ([IdGroupeSecurite]) REFERENCES [dbo].[GroupeSecurite] ([IdGroupeSecurite])
</code>```

Now what?

答:
I found it! Here's my solution, in case someone else tumbles with the same problem.

For some strange reason, Visual Studio added a '1' at the end of some of my Many-to-Many tables name. Entity Framework did not like it (neither did I), so I renamed them in my model:

Example:

```<code>public Employe()
{
    this.AccesApplicatif1 = new HashSet<AccesApplicatif>();
    this.TelephoneCellulaire1 = new HashSet<TelephoneCellulaire>();
    this.CleBatiment1 = new HashSet<CleBatiment>();
    this.EquipementInfo = new HashSet<EquipementInfo>();
    this.GroupeSecurite1 = new HashSet<GroupeSecurite>();
    this.VehiculeCompagnie1 = new HashSet<VehiculeCompagnie>();
    this.Employe1 = new HashSet<Employe>();
}
</code>```

Became:

```<code>this.AccesApplicatif = new HashSet<AccesApplicatif>();
this.TelephoneCellulaire = new HashSet<TelephoneCellulaire>();
this.CleBatiment = new HashSet<CleBatiment>();
this.EquipementInfo = new HashSet<EquipementInfo>();
this.GroupeSecurite = new HashSet<GroupeSecurite>();
this.VehiculeCompagnie = new HashSet<VehiculeCompagnie>();
this.Employe1 = new HashSet<Employe>();
</code>```

Visual Studio was intelligent enough to rename them in pretty much everything, except in my Entities.edmx, Views and my Metadata. I took great care of it and now, verything work like a charm. I still don't understand why I was able to Edit my employes though...

Body:
I have a problem with the project I am working on. On POST:Edit, it saves my changes. On POST:Create, I receive this error: "Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values."

So I did what my teachers taught us in College: I just Googled it. The answers however were suggesting to change the ModelBuilder-fluent API. I do not think this would be inappropriate since I use Database-First approach (It says it is only for Code-First) AND my Save is functional in Edit. Since I wanted to work with ViewModels, I followed this tutorial. I even found and posted a solution for the tutorial about the Create method to help me with my problem. Please help me. I am about to throw my computer out of the window. Which is kind of complicated because they are made of tempered glass.

So here's the metadata for my model (with minimal data annotation for readability sake:

public partial class Employe
{
    sealed class Metadata
    {
        [Key]
        public int IdEmploye { get; set; }

        public string NomEmploye { get; set; }

        public string PrenomEmploye { get; set; }

        [ForeignKey("TitreEmploye_IdTitre")]
        public int IdTitre { get; set; }

        [ForeignKey("Departement_IdDepartement")]
        public int IdDepartement { get; set; }

        [ForeignKey("Employe_IdSuperviseur")]
        public int IdSuperviseur { get; set; }

        public System.DateTime DateEmbauche { get; set; }

        public Nullable<System.DateTime> DateDepart { get; set; }

        public string StatutEmploye { get; set; }

        [ForeignKey("Employeur_IdEmployeur")]
        public int IdEmployeur { get; set; }

        [ForeignKey("Localisation_IdLocalisation")]
        public int IdLocalisation { get; set; }

        public string Langue { get; set; }

        public Nullable<bool> CarteAcces { get; set; }

        [ForeignKey("TelephoneBureau_IdTelephoneBureau")]
        public Nullable<int> IdTelephoneBureau { get; set; }

        public Nullable<bool> CarteAffaire { get; set; }

        public string AdresseCourriel { get; set; }

        public bool CodeAlarme { get; set; }

        public System.DateTime DateNaissance { get; set; }

        public Nullable<bool> IsSuperviseur { get; set; }

        public Nullable<bool> IsActif { get; set; }
    }
}

}

Here's my problematic(?) model:

public partial class Employe
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public Employe()
    {
        this.AccesApplicatif1 = new HashSet<AccesApplicatif>();
        this.TelephoneCellulaire1 = new HashSet<TelephoneCellulaire>();
        this.CleBatiment1 = new HashSet<CleBatiment>();
        this.EquipementInfo = new HashSet<EquipementInfo>();
        this.GroupeSecurite1 = new HashSet<GroupeSecurite>();
        this.VehiculeCompagnie1 = new HashSet<VehiculeCompagnie>();
        this.Employe1 = new HashSet<Employe>();
    }

    public int IdEmploye { get; set; }
    public string NomEmploye { get; set; }
    public string PrenomEmploye { get; set; }
    public int IdTitre { get; set; }
    public int IdDepartement { get; set; }
    public int IdSuperviseur { get; set; }
    public System.DateTime DateEmbauche { get; set; }
    public Nullable<System.DateTime> DateDepart { get; set; }
    public string StatutEmploye { get; set; }
    public int IdEmployeur { get; set; }
    public int IdLocalisation { get; set; }
    public string Langue { get; set; }
    public Nullable<bool> CarteAcces { get; set; }
    public Nullable<int> IdTelephoneBureau { get; set; }
    public Nullable<bool> CarteAffaire { get; set; }
    public string AdresseCourriel { get; set; }
    public bool CodeAlarme { get; set; }
    public System.DateTime DateNaissance { get; set; }
    public Nullable<bool> IsSuperviseur { get; set; }
    public Nullable<bool> IsActif { get; set; }

    public virtual Departement Departement { get; set; }
    public virtual Employeur Employeur { get; set; }
    public virtual Localisation Localisation { get; set; }
    public virtual TelephoneBureau TelephoneBureau { get; set; }
    public virtual TitreEmploye TitreEmploye { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<AccesApplicatif> AccesApplicatif1 { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<TelephoneCellulaire> TelephoneCellulaire1 { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<CleBatiment> CleBatiment1 { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<EquipementInfo> EquipementInfo { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<GroupeSecurite> GroupeSecurite1 { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<VehiculeCompagnie> VehiculeCompagnie1 { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Employe> Employe1 { get; set; }
    public virtual Employe Employe2 { get; set; }

    public string NomSuperviseur
    {
        get
        {
            return string.Format("{0} {1}", PrenomEmploye, NomEmploye);
        }
    }
}

As I said, since I wanted to work with ViewModels, here's the culprit:

public partial class EmployeVM
{
    public Employe Employe { get; set; } //Employe

    public string NomEmploye { get; set; } //Employe

    public string PrenomEmploye { get; set; } //Employe

    public DateTime DateNaissance { get; set; } //Employe

    public string Langue { get; set; } //Employe

    //////////////////////////////////////////////////////////////
    public IEnumerable<Titre> Titres { get; set; } //TitreEmploye
    public class Titre
    {
        public string description { get; set; } //TitreEmploye
    }

    //////////////////////////////////////////////////////////////
    public IEnumerable<Departement> Departements { get; set; } //Departement
    public class Departement
    {
        public string description { get; set; } //Departement
    }

    //////////////////////////////////////////////////////////////
    public IEnumerable<Superviseur> Superviseurs { get; set; } //Employe
    public class Superviseur
    {
        public string nomSuperviseur { get; set; } //Employe
    }

    public string StatutEmploye { get; set; } //Employe

    public DateTime DateEmbauche { get; set; } //Employe

    public Nullable<System.DateTime> DateDepart { get; set; } //Employe

    //////////////////////////////////////////////////////////////
    public IEnumerable<Employeur> Employeurs { get; set; } //Employeur
    public class Employeur
    {
        public string nomEmployeur { get; set; } //Employeur
    }

    //////////////////////////////////////////////////////////////
    public IEnumerable<Localisation> Localisations { get; set; } //Localisation
    public class Localisation
    {
        public string description { get; set; } //Localisation
    }

    public bool CarteAcces { get; set; } //Employe

    //////////////////////////////////////////////////////////////
    public IEnumerable<TelephoneBureau> TelephoneBureaux { get; set; } //TelephoneBureau
    public class TelephoneBureau
    {
        public string extension { get; set; } //TelephoneBureau
    }

    //////////////////////////////////////////////////////////////
    public IEnumerable<SelectListItem> AllTelephoneCellulaires { get; set; } //TelephoneCellulaire
    private List<int> _selectedTelephoneCellulaires;
    public List<int> SelectedTelephoneCellulaires
    {
        get
        {
            if (_selectedTelephoneCellulaires == null)
            {
                _selectedTelephoneCellulaires = Employe.TelephoneCellulaire1.Select(m => m.IdTelephoneCellulaire).ToList();
            }
            return _selectedTelephoneCellulaires;
        }
        set { _selectedTelephoneCellulaires = value; }
    }

    public bool CarteAffaire { get; set; } //Employe

    //////////////////////////////////////////////////////////////
    public IEnumerable<SelectListItem> AllEquipementInformatiques { get; set; } //EquipementInfo
    private List<int> _selectedEquipementInformatiques;
    public List<int> SelectedEquipementInformatiques
    {
        get
        {
            if (_selectedEquipementInformatiques == null)
            {
                _selectedEquipementInformatiques = Employe.EquipementInfo.Select(m => m.IdEquipementInfo).ToList();
            }
            return _selectedEquipementInformatiques;
        }
        set { _selectedEquipementInformatiques = value; }
    }

    public string AdresseCourriel { get; set; } //Employe

    //////////////////////////////////////////////////////////////
    public IEnumerable<SelectListItem> AllGroupeSecurites { get; set; } //GroupeSecurite
    private List<int> _selectedGroupeSecurites;
    public List<int> SelectedGroupeSecurites
    {
        get
        {
            if (_selectedGroupeSecurites == null)
            {
                _selectedGroupeSecurites = Employe.GroupeSecurite1.Select(m => m.IdGroupeSecurite).ToList();
            }
            return _selectedGroupeSecurites;
        }
        set { _selectedGroupeSecurites = value; }
    }

    //////////////////////////////////////////////////////////////
    public IEnumerable<SelectListItem> AllAccesApplicatifs { get; set; } //AccesApplicatif
    private List<int> _selectedAccesApplicatifs;
    public List<int> SelectedAccesApplicatifs
    {
        get
        {
            if (_selectedAccesApplicatifs == null)
            {
                _selectedAccesApplicatifs = Employe.AccesApplicatif1.Select(m => m.IdAccesApplicatif).ToList();
            }
            return _selectedAccesApplicatifs;
        }
        set { _selectedAccesApplicatifs = value; }
    }

    public bool CodeAlarme { get; set; } //Employe

    //////////////////////////////////////////////////////////////
    public IEnumerable<SelectListItem> AllCleBatiments { get; set; } //CleBatiment
    private List<int> _selectedCleBatiments;
    public List<int> SelectedCleBatiments
    {
        get
        {
            if (_selectedCleBatiments == null)
            {
                _selectedCleBatiments = Employe.CleBatiment1.Select(m => m.IdCleBatiment).ToList();
            }
            return _selectedCleBatiments;
        }
        set { _selectedCleBatiments = value; }
    }

    //////////////////////////////////////////////////////////////
    public IEnumerable<SelectListItem> AllVehiculeCompagnies { get; set; } //VehiculeCompagnie
    private List<int> _selectedVehiculeCompagnies;
    public List<int> SelectedVehiculeCompagnies
    {
        get
        {
            if (_selectedVehiculeCompagnies == null)
            {
                _selectedVehiculeCompagnies = Employe.VehiculeCompagnie1.Select(m => m.IdVehiculeCompagnie).ToList();
            }
            return _selectedVehiculeCompagnies;
        }
        set { _selectedVehiculeCompagnies = value; }
    }

    public bool IsSuperviseur { get; set; } //Employe

    public bool IsActif { get; set; } //Employe

    public EmployeVM()
    {
        AllTelephoneCellulaires = new List<SelectListItem>();
        AllEquipementInformatiques = new List<SelectListItem>();
        AllGroupeSecurites = new List<SelectListItem>();
        AllAccesApplicatifs = new List<SelectListItem>();
        AllCleBatiments = new List<SelectListItem>();
        AllVehiculeCompagnies = new List<SelectListItem>();
    }
}

And here's the Create part of my Controller (I KNOW I will have to add some methods to comply to DRY, but for now, that's what it is:

// GET: Employes/Create
    //[AcceptVerbs(HttpVerbs.Get), ImportModelStateFromTempData]
    public ActionResult Create()
    {
        var employeView = new EmployeVM();

        //Population pour les ListBoxFor
        var allTelephoneCellulaireActifList = db.TelephoneCellulaireActif.ToList();
        ViewBag.AllTelephoneCellulaires = allTelephoneCellulaireActifList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdTelephoneCellulaire.ToString()
        });
        var allEquipementInfoActifList = db.EquipementInfoActif.ToList();
        ViewBag.AllEquipementInformatiques = allEquipementInfoActifList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdEquipementInfo.ToString()
        });
        var allGroupeSecuriteList = db.GroupeSecurite.ToList();
        ViewBag.AllGroupeSecurites = allGroupeSecuriteList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdGroupeSecurite.ToString()
        });
        var allAccesApplicatifActifList = db.AccesApplicatifActif.ToList();
        ViewBag.AllAccesApplicatifs = allAccesApplicatifActifList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdAccesApplicatif.ToString()
        });
        var allCleBatimentList = db.CleBatiment.ToList();
        ViewBag.AllCleBatiments = allCleBatimentList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdCleBatiment.ToString()
        });
        var allVehiculeCompagnieActifList = db.VehiculeCompagnieActif.ToList();
        ViewBag.AllVehiculeCompagnies = allVehiculeCompagnieActifList.Select(o => new SelectListItem
        {
            Text = o.DescriptionVehicule,
            Value = o.IdVehiculeCompagnie.ToString()
        });

        //Zero-or-One-to-Many relationships
        List<TitreEmployeActif> ListeTitreEmployeActif = db.TitreEmployeActif.OrderBy(titre => titre.Description).ToList();
        ViewBag.IdTitre = new SelectList(ListeTitreEmployeActif, "IdTitre", "Description");

        List<Departement> ListeDepartement = db.Departement.OrderBy(departement => departement.Description).ToList();
        ViewBag.IdDepartement = new SelectList(ListeDepartement, "IdDepartement", "Description");

        List<EmployeSuperviseurActif> ListeEmployeSuperviseurActif = db.EmployeSuperviseurActif.OrderBy(sup => sup.PrenomNom).ToList();
        ViewBag.IdSuperviseur = new SelectList(ListeEmployeSuperviseurActif, "IdEmploye", "PrenomNom");

        List<Employeur> ListeEmployeur = db.Employeur.OrderBy(employeur => employeur.NomEmployeur).ToList();
        ViewBag.IdEmployeur = new SelectList(ListeEmployeur, "IdEmployeur", "NomEmployeur");

        List<Localisation> ListeLocalisation = db.Localisation.OrderBy(localisation => localisation.Description).ToList();
        ViewBag.IdLocalisation = new SelectList(ListeLocalisation, "IdLocalisation", "Description");

        List<TelephoneBureauActif> ListeTelephoneBureauActif = db.TelephoneBureauActif.OrderBy(phone => phone.Extension).ToList();
        ViewBag.IdTelephoneBureau = new SelectList(ListeTelephoneBureauActif, "IdTelephoneBureau", "Extension");

        return View();
    }

    // POST: Employes/Create
    // To protect from overposting attacks, please enable the specific properties you want to bind to,
    // for more details see http://go.microsoft.com/fwlink/?LinkId=317598.
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create(EmployeVM employeView)
    {
        if (!ModelState.IsValid)
        {
            foreach (var obj in ModelState.Values)
            {
                foreach (var error in obj.Errors)
                {
                    if (!string.IsNullOrEmpty(error.ErrorMessage))
                        System.Diagnostics.Debug.WriteLine("ERROR WHY = " + error.ErrorMessage);
                }
            }
        }

        if (ModelState.IsValid)
        {
            var employeToAdd = db.Employe
                .Include(e => e.TelephoneCellulaire1)
                .Include(e => e.EquipementInfo)
                .Include(e => e.GroupeSecurite1)
                .Include(e => e.AccesApplicatif1)
                .Include(e => e.CleBatiment1)
                .Include(e => e.VehiculeCompagnie1)
                .First();

            if (TryUpdateModel(employeToAdd, "Employe", new string[] { "IdEmploye", "NomEmploye", "PrenomEmploye", "IdTitre", "IdDepartement", "IdSuperviseur", "DateEmbauche", "DateDepart", "StatutEmploye", "IdEmployeur", "IdLocalisation", "Langue", "CarteAcces", "TelephoneCellulaire", "IdTelephoneBureau", "CarteAffaire", "EquipementInformatique", "AdresseCourriel", "GroupeSecurite", "AccesApplicatif", "CodeAlarme", "CleBatiment", "VehiculeCompagnie", "DateNaissance", "IsSuperviseur", "IsActif" }))
            {
                var updatedTelephoneCellulaires = new HashSet<int>(employeView.SelectedTelephoneCellulaires);
                var updatedEquipementInformatiques = new HashSet<int>(employeView.SelectedEquipementInformatiques);
                var updatedGroupeSecurites = new HashSet<int>(employeView.SelectedGroupeSecurites);
                var updatedAccesApplicatifs = new HashSet<int>(employeView.SelectedAccesApplicatifs);
                var updatedCleBatiments = new HashSet<int>(employeView.SelectedCleBatiments);
                var updatedVehiculeCompagnies = new HashSet<int>(employeView.SelectedVehiculeCompagnies);

                //Prochaine ligne db.TelephoneCellulaire1 !!! ou db.TelephoneCellulaireActif ???  Check readonly
                foreach (TelephoneCellulaire telephone in db.TelephoneCellulaire)
                {
                    if (!updatedTelephoneCellulaires.Contains(telephone.IdTelephoneCellulaire))
                    {
                        employeToAdd.TelephoneCellulaire1.Remove(telephone);
                    }
                    else
                    {
                        employeToAdd.TelephoneCellulaire1.Add(telephone);
                    }
                }
                foreach (EquipementInfo equipement in db.EquipementInfo)
                {
                    if (!updatedEquipementInformatiques.Contains(equipement.IdEquipementInfo))
                    {
                        employeToAdd.EquipementInfo.Remove(equipement);
                    }
                    else
                    {
                        employeToAdd.EquipementInfo.Add(equipement);
                    }
                }
                foreach (GroupeSecurite groupe in db.GroupeSecurite)
                {
                    if (!updatedGroupeSecurites.Contains(groupe.IdGroupeSecurite))
                    {
                        employeToAdd.GroupeSecurite1.Remove(groupe);
                    }
                    else
                    {
                        employeToAdd.GroupeSecurite1.Add(groupe);
                    }
                }
                foreach (AccesApplicatif acces in db.AccesApplicatif)
                {
                    if (!updatedAccesApplicatifs.Contains(acces.IdAccesApplicatif))
                    {
                        employeToAdd.AccesApplicatif1.Remove(acces);
                    }
                    else
                    {
                        employeToAdd.AccesApplicatif1.Add(acces);
                    }
                }
                foreach (CleBatiment cle in db.CleBatiment)
                {
                    if (!updatedCleBatiments.Contains(cle.IdCleBatiment))
                    {
                        employeToAdd.CleBatiment1.Remove(cle);
                    }
                    else
                    {
                        employeToAdd.CleBatiment1.Add(cle);
                    }
                }
                foreach (VehiculeCompagnie vehicule in db.VehiculeCompagnie)
                {
                    if (!updatedVehiculeCompagnies.Contains(vehicule.IdVehiculeCompagnie))
                    {
                        employeToAdd.VehiculeCompagnie1.Remove(vehicule);
                    }
                    else
                    {
                        employeToAdd.VehiculeCompagnie1.Add(vehicule);
                    }
                }
            }
            db.Employe.Add(employeToAdd);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        var allTelephoneCellulaireActifList = db.TelephoneCellulaireActif.ToList();
        ViewBag.AllTelephoneCellulaires = allTelephoneCellulaireActifList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdTelephoneCellulaire.ToString()
        });
        var allEquipementInfoActifList = db.EquipementInfoActif.ToList();
        ViewBag.AllEquipementInformatiques = allEquipementInfoActifList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdEquipementInfo.ToString()
        });
        var allGroupeSecuriteList = db.GroupeSecurite.ToList();
        ViewBag.AllGroupeSecurites = allGroupeSecuriteList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdGroupeSecurite.ToString()
        });
        var allAccesApplicatifActifList = db.AccesApplicatifActif.ToList();
        ViewBag.AllAccesApplicatifs = allAccesApplicatifActifList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdAccesApplicatif.ToString()
        });
        var allCleBatimentList = db.CleBatiment.ToList();
        ViewBag.AllCleBatiments = allCleBatimentList.Select(o => new SelectListItem
        {
            Text = o.Description,
            Value = o.IdCleBatiment.ToString()
        });
        var allVehiculeCompagnieActifList = db.VehiculeCompagnieActif.ToList();
        ViewBag.AllVehiculeCompagnies = allVehiculeCompagnieActifList.Select(o => new SelectListItem
        {
            Text = o.DescriptionVehicule,
            Value = o.IdVehiculeCompagnie.ToString()
        });

        //Zero-or-One-to-Many relationships
        List<TitreEmployeActif> ListeTitreEmployeActif = db.TitreEmployeActif.OrderBy(titre => titre.Description).ToList();
        ViewBag.IdTitre = new SelectList(ListeTitreEmployeActif, "IdTitre", "Description");

        List<Departement> ListeDepartement = db.Departement.OrderBy(departement => departement.Description).ToList();
        ViewBag.IdDepartement = new SelectList(ListeDepartement, "IdDepartement", "Description");

        List<EmployeSuperviseurActif> ListeEmployeSuperviseurActif = db.EmployeSuperviseurActif.OrderBy(sup => sup.PrenomNom).ToList();
        ViewBag.IdSuperviseur = new SelectList(ListeEmployeSuperviseurActif, "IdEmploye", "PrenomNom");

        List<Employeur> ListeEmployeur = db.Employeur.OrderBy(employeur => employeur.NomEmployeur).ToList();
        ViewBag.IdEmployeur = new SelectList(ListeEmployeur, "IdEmployeur", "NomEmployeur");

        List<Localisation> ListeLocalisation = db.Localisation.OrderBy(localisation => localisation.Description).ToList();
        ViewBag.IdLocalisation = new SelectList(ListeLocalisation, "IdLocalisation", "Description");

        List<TelephoneBureauActif> ListeTelephoneBureauActif = db.TelephoneBureauActif.OrderBy(phone => phone.Extension).ToList();
        ViewBag.IdTelephoneBureau = new SelectList(ListeTelephoneBureauActif, "IdTelephoneBureau", "Extension");

        return View(employeView);
    }

And just to complete the picture, an extract from Create.cshtml:

        @Html.LabelFor(model => model.AllEquipementInformatiques, "Équipements informatiques", htmlAttributes: new { @class = "control-label col-md-2" })

            @Html.ListBoxFor(model => model.SelectedEquipementInformatiques, (IEnumerable<SelectListItem>)ViewBag.AllEquipementInformatiques, new { @class = "form-control" })

Speaking about a picture, here's a little capture of one of my Many-to-Many table, with data entered with Edit:

Employe_VehiculeCompagnie

The thing to know (and I think it might be part of the problem) is: all of the 6 Many-To-Many relationships are optional. But even when I try to create a new Employe with at least one item in each of the 6 Many-to-Many field, it throws that error. And it still works in Edit. Questions: why this error is thrown and how can I make my app works? Any help would be greatly appreciated.

Edit:
Should I add this? One of my join table:

CREATE TABLE [dbo].[Employe_GroupeSecurite] (
[IdEmploye]        INT NOT NULL,
[IdGroupeSecurite] INT NOT NULL,
PRIMARY KEY CLUSTERED ([IdEmploye] ASC, [IdGroupeSecurite] ASC),
CONSTRAINT [FK_Employe_GroupeSecurite_Employe] FOREIGN KEY ([IdEmploye]) REFERENCES [dbo].[Employe] ([IdEmploye]),
CONSTRAINT [FK_Employe_GroupeSecurite_GroupeSecurite] FOREIGN KEY ([IdGroupeSecurite]) REFERENCES [dbo].[GroupeSecurite] ([IdGroupeSecurite])

Now what?

Body:
I found it! Here's my solution, in case someone else tumbles with the same problem.

For some strange reason, Visual Studio added a '1' at the end of some of my Many-to-Many tables name. Entity Framework did not like it (neither did I), so I renamed them in my model:

Example:

public Employe()
{
    this.AccesApplicatif1 = new HashSet<AccesApplicatif>();
    this.TelephoneCellulaire1 = new HashSet<TelephoneCellulaire>();
    this.CleBatiment1 = new HashSet<CleBatiment>();
    this.EquipementInfo = new HashSet<EquipementInfo>();
    this.GroupeSecurite1 = new HashSet<GroupeSecurite>();
    this.VehiculeCompagnie1 = new HashSet<VehiculeCompagnie>();
    this.Employe1 = new HashSet<Employe>();
}

Became:

this.AccesApplicatif = new HashSet<AccesApplicatif>();
this.TelephoneCellulaire = new HashSet<TelephoneCellulaire>();
this.CleBatiment = new HashSet<CleBatiment>();
this.EquipementInfo = new HashSet<EquipementInfo>();
this.GroupeSecurite = new HashSet<GroupeSecurite>();
this.VehiculeCompagnie = new HashSet<VehiculeCompagnie>();
this.Employe1 = new HashSet<Employe>();

Visual Studio was intelligent enough to rename them in pretty much everything, except in my Entities.edmx, Views and my Metadata. I took great care of it and now, verything work like a charm. I still don't understand why I was able to Edit my employes though...


问:
How to not return a value of 0 when data does not exist in table, SQLPLUS
I have two tables, table A and B, and I am counting the number of occurences of a data type from table A,

```<code>    ENAME       SALES
    ---------- ----------
    Wilson          0
    Fox             1
    Wang            2
    Green           1
    Fox             0
    Phillips        2
    Loftus          0
    Smith           2
    Smith           3
    Wolf            2
    Jones           1
    Liu             0
</code>```

Where when the sales count is 0, the ename does not exist in table B at all.

How would I go about removing the 0 count? I'm trying to get the return to look like this:

```<code>    ENAME       SALES
    ---------- ----------
    Wilson
    Fox             1
    Wang            2
    Green           1
    Fox
    Phillips        2
    Loftus
    Smith           2
    Smith           3
    Wolf            2
    Jones           1
    Liu
</code>```

答:
One method uses case, another nullif():

```<code>select ename, nullif(sales, 0) as sales
from t;
</code>```

If this is an aggregation query:

```<code>select ename, nullif(count(*), 0) as sales
from t
group by ename;
</code>```

Body:
I have two tables, table A and B, and I am counting the number of occurences of a data type from table A,

    ENAME       SALES
    ---------- ----------
    Wilson          0
    Fox             1
    Wang            2
    Green           1
    Fox             0
    Phillips        2
    Loftus          0
    Smith           2
    Smith           3
    Wolf            2
    Jones           1
    Liu             0

Where when the sales count is 0, the ename does not exist in table B at all.

How would I go about removing the 0 count? I'm trying to get the return to look like this:

    ENAME       SALES
    ---------- ----------
    Wilson
    Fox             1
    Wang            2
    Green           1
    Fox
    Phillips        2
    Loftus
    Smith           2
    Smith           3
    Wolf            2
    Jones           1
    Liu

Body:
One method uses case, another nullif():

select ename, nullif(sales, 0) as sales
from t;

If this is an aggregation query:

select ename, nullif(count(*), 0) as sales
from t
group by ename;


问:
Is it possible read XML files that are linked to within another XML file "all in one go"?
I have an XML file stored on a server which contains elements, of which some are refererences to other xml files e.g.

```<code><xml>
<item>value</item>
<data>http://www.example.org/item1.xml</data>
<data>http://www.example.org/item2.xml</data>
</xml>
</code>```

Where item1 and item2 are like this for example:

```<code><item>
  <id>1</id>
  <name>Item One</name>
</item>
</code>```

I want to be able to read the main XML file (which of course I can do) this is done with an Asyncronous web request to download the XML - would it be possible to read the XML files referenced within the XML file in the same "request" rather than spin up, in this case two more seperate webclient requests to download these, as because these would be asyncronous too and therefore this data would not be available until those requests have completed - for binding to a UI in XAML for instance.

This would result in the main xml file being downloaded and completed and then the two xml files being seperately downloaded too.  Is it possible to read the main xml and the "sub xml" files all in one go?

I can only use Async webrequests as this is a platform limitation of Silverlight and I cannot change the data as it is distibuted between many XML files to save server storage and is in a provided format, can the main and sub XML files be downloaded and parsed in one request, using LINQ / XElement / Silverlight supported features - I cannot use XPath as this would not be supported.

答:
If I understood you correctly, you want to establish a relation between a generic item.xml and lots of subitem.xml files. (right ?)

Then you should rather use a relational database instead of trying to connect xml files.
Or put all together in one file, as long as it's not getting to big.
Everything else is waste of your time. :)

ContentLicense: CC BY-SA 2.5

Body:
I have an XML file stored on a server which contains elements, of which some are refererences to other xml files e.g.

<xml>
<item>value</item>
<data>http://www.example.org/item1.xml</data>
<data>http://www.example.org/item2.xml</data>
</xml>

Where item1 and item2 are like this for example:

<item>
  <id>1</id>
  <name>Item One</name>
</item>

I want to be able to read the main XML file (which of course I can do) this is done with an Asyncronous web request to download the XML - would it be possible to read the XML files referenced within the XML file in the same "request" rather than spin up, in this case two more seperate webclient requests to download these, as because these would be asyncronous too and therefore this data would not be available until those requests have completed - for binding to a UI in XAML for instance.

This would result in the main xml file being downloaded and completed and then the two xml files being seperately downloaded too.  Is it possible to read the main xml and the "sub xml" files all in one go?

I can only use Async webrequests as this is a platform limitation of Silverlight and I cannot change the data as it is distibuted between many XML files to save server storage and is in a provided format, can the main and sub XML files be downloaded and parsed in one request, using LINQ / XElement / Silverlight supported features - I cannot use XPath as this would not be supported.


问:
WCAG 2.0 Compliance checker
Have a requirement to make website compatible for visually challenged
people (WCAG 2.0 Compliance).
Found an online tool Achecker,but it seems to be not identifying html 5/bootstrap
properties.
It would be helpful if anybody can recommend any online tool to check whether the
changes made to make website compatible with wcag guidelines are correct?

Thanks

答:
I think the most popular checker is the WAVE WebAim checker: http://wave.webaim.org/

A stricter checker is Cryptzone's CynthiaSays: http://www.cynthiasays.com/

I use both. I start with WebAim and once I've ironed out those issues I move onto Cryptzone.

Title: WCAG 2.0 Compliance checker