I added the leftjoin following your recommendation above. Maybe I got that wrong. Removing the leftjoin gives me the error below:
System.ArgumentException
HResult=0x80070057
Message=An item with the same key has already been added.
Source=mscorlib
StackTrace:
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add)at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value)
at DataTables.Editor._InsertOrUpdateTable(String table, Dictionary2 values, Dictionary2 where) in /home/vagrant/DataTablesSrc/extensions/Editor-NET/DataTables-Editor-Server/Editor.cs:line 2204
After selecting the files for upload entries get created in UserFiles. It looks like it's trying to add them again after clicking save.
If I use below code for the upload and create processes, I am able to upload the files. UserFiles table gets populated with the files but when saving (ie create stage) from editor I get error below. AutoCDRFiles table does not show any record.
Error:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=DataTables-Editor-Server
StackTrace:
at DataTables.MJoin.Insert(Editor editor, Object parentId, Dictionary`2 data) in /home/vagrant/DataTablesSrc/extensions/Editor-NET/DataTables-Editor-Server/MJoin.cs:line 510
If I use the code you last gave me for the upload and create processes, uploading stumbles and I get error below. There is nothing in either table. I confirm it is a 1-1 relation I need but it seems this is missing something as at least the files get uploaded with the MJoin code above.
Error:
System.Exception
HResult=0x80131500
Message=Unknown upload field name submitted
Source=DataTables-Editor-Server
StackTrace:
at DataTables.Editor._Upload(DtRequest data) in /home/vagrant/DataTablesSrc/extensions/Editor-NET/DataTables-Editor-Server/Editor.cs:line 1659
If I use a mixture of both, ie 1st code for upload process and 2nd code for create I do get a line in AutoCDRFiles but only for the last file I try to upload and field UserFileID, holding the id from UserFiles is empty.
If I use .Field(new Field("AutoCDRFiles[].UserFileID"), upload goes through but saving does not. Error is:
System.Data.SqlClient.SqlException
HResult=0x80131904
Message=Invalid column name 'AutoCDRFiles[].[UserFileID'.
Source=.Net SqlClient Data Provider
StackTrace:
<Cannot evaluate the exception stack trace>
I'd be grateful for a reply as I really wish to move on from this issue.
Let's go with test #2 as its a 1:1 relationship a leftjoin should be used (its way faster than an Mjoin).
You are currently getting:
Message=Unknown upload field name submitted
Which suggests that the field name on the client-side for the upload is not the same as what you have on the server-side:
editor.Field(new Field("AutoCDRFiles.UserFileID")
From the other posts in your thread above, it looks like you might have array syntax in the field name (fields.name) but without being able to see your Javascript I can't say for sure.
So I's say go to test #2 and check that the field name matches the field that you've attached the Upload to on the server-side.
If I put name: 'AutoCDRFiles.UserFileID', instead of name: 'AutoCDRFiles[].UserFileID' to match the server side editor.Field(new Field("AutoCDRFiles.UserFileID"), I get:
System.ArgumentException
HResult=0x80070057
Message=No mapping exists from object type System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] to a known managed provider native type.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
Thanks for the clarification - I'd assumed that the Javascript there was for the Mjoin test. As I say, don't use the array syntax in the field name - use AutoCDRFiles.UserFileID - it has to match the server-side. I also am assuming that you've removed the Mjoin completely from the server-side code (which I'm not certain is the case given that your last post above doesn't just give an 'unknown upload field name' error.
Could you show me the Javascript code and C# controller that you have with those changes so I'm fully up to date please?
I think there might be some confusion on my part. As I indicated in this thread it works fine with upload. I need to upload multiple files and each file has one entry in autocdrfiles and one entry in userfiles tables. I thought that was what was meant with one-to-one.
So it seems I do need an MJoin? As test #1 above indicates the upload works and but I get only one entry in autocdrfiles table no matter how many files I try to upload and that entry has no id in its userfileid field. Can you help? Thanks as ever.
Okay, yup, let's both get on the same page before we mess around with much more code!
You are using:
editor = new Editor(db, "AutoCDRFiles")
which means the Editor is editing the AutoCDRFiles table. You note above that this table has 1:1 with the UserFiles table.
I'm not clear on the multiple files aspect. Every entry in AutoCDRFiles will be represented by a single row in a DataTable. If you wanted multiple grouped together you'd need a grouping row in a separate database table.
I'm not quite understanding that - sorry if I'm being denser than normal here!
If you have each row in the AutoCDRFiles table shown as a row in the DataTable and you have a 1:1 relationship for the files, then where would the multiple files upload come into play?
Are you looking to have a create form that can accept multiple files for upload ins a single go and that would create multiple rows in the AutoCDRFiles table? If so, I'm afraid that's not a feature that Editor supports at the moment. One "Create" view === one row in the database is how it works.
Are you looking to have a create form that can accept multiple files for upload ins a single go and that would create multiple rows in the AutoCDRFiles table?
Yes.
Each uploaded file would have a row in AutoCDRFiles.
Is that likely to be supported? If so do you have a timescale?
I use a table (userfiles) to keep basic and common parameters to do with the users' uploaded files such as the name, path, size of files. To have to use your model means I will have to move all the disperate fields that I currently use in all my tables that deal with uploaded files to that table. That does not make a lot of sense.
Ah okay - that's why I wasn't getting it before. I'm afraid that this is not a feature that is on our roadmap since its the first time its come up!
It is possible to use create() to create multiple new rows at once, but that wouldn't work for multiple images since that is embedded into the form - i.e. if we went that way, each new row would all have the same image values!
To have to use your model means I will have to move all the disperate fields that I currently use in all my tables that deal with uploaded files to that table. That does not make a lot of sense.
I agree - it doesn't. I'm not sure why you would need to move the various fields?
Right - but isn't that the point of having a central table for storing file meta information? Any other table that needs to reference a file can just use a left join link to the central files table, which then has the general file information such as extension, size, etc.
That way any information that is specific to the host table is held in the host table while generic file information is held in the files table.
AutoCDRFile does not hold file meta information. The files are analysed by the programme and hold other fields specific to those tasks (ie different from meta info about the file), such as the scan date, if the scan was successful, the scan type,...).
"Any other table that needs to reference a file can just use a left join link to the central files table"
This would presuppose, again, that I would have to move all the fields about the scan to that files table when that files table should only hold meta info about the file and nothing else.
Answers
Thank you. Will try that.
Hi
I added the leftjoin following your recommendation above. Maybe I got that wrong. Removing the leftjoin gives me the error below:
System.ArgumentException
HResult=0x80070057
Message=An item with the same key has already been added.
Source=mscorlib
StackTrace:
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary
2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary
2.Add(TKey key, TValue value)at DataTables.Editor._InsertOrUpdateTable(String table, Dictionary
2 values, Dictionary
2 where) in /home/vagrant/DataTablesSrc/extensions/Editor-NET/DataTables-Editor-Server/Editor.cs:line 2204After selecting the files for upload entries get created in UserFiles. It looks like it's trying to add them again after clicking save.
Let's go back to this:
You want to use either a left join and an Mjoin. Not both.
So the question is, do you want one
UserFiles
entry perAutoCDRFiles
entry or multiple?Allan
Hi
Yes it is one UserFiles entry per AutoCDRFiles entry. Thanks.
Would you have any news on this please?
Apologies - I missed your reply before. If its a single entry, then a left join is the way to go and an Mjoin is not required at all.
Let's try this:
That will read the data from your
AutoCDRFiles
(the model) and alsoUserFiles
for the left join.Allan
Many thanks. Will try that.
Many thanks. Will try that.
Hi
Thanks for your patience with this.
Test #1:
If I use below code for the upload and create processes, I am able to upload the files. UserFiles table gets populated with the files but when saving (ie create stage) from editor I get error below. AutoCDRFiles table does not show any record.
Error:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=DataTables-Editor-Server
StackTrace:
at DataTables.MJoin.Insert(Editor editor, Object parentId, Dictionary`2 data) in /home/vagrant/DataTablesSrc/extensions/Editor-NET/DataTables-Editor-Server/MJoin.cs:line 510
Code:
Test #2:
If I use the code you last gave me for the upload and create processes, uploading stumbles and I get error below. There is nothing in either table. I confirm it is a 1-1 relation I need but it seems this is missing something as at least the files get uploaded with the MJoin code above.
Error:
System.Exception
HResult=0x80131500
Message=Unknown upload field name submitted
Source=DataTables-Editor-Server
StackTrace:
at DataTables.Editor._Upload(DtRequest data) in /home/vagrant/DataTablesSrc/extensions/Editor-NET/DataTables-Editor-Server/Editor.cs:line 1659
Code:
Test #3:
If I use a mixture of both, ie 1st code for upload process and 2nd code for create I do get a line in AutoCDRFiles but only for the last file I try to upload and field UserFileID, holding the id from UserFiles is empty.
Thank you.
For Test #2, I'm checking for any conflict with the field name in js code.
I believe the field name is correct "name: 'AutoCDRFiles[].UserFileID',"
Code:
If I cange from uploadMany to upload and modify what is needed in the code everything works. I'm pretty sure the issue is the field name under
editor.Field(new Field("AutoCDRFiles.UserFileID")
If I use .Field(new Field("AutoCDRFiles[].UserFileID"), upload goes through but saving does not. Error is:
System.Data.SqlClient.SqlException
HResult=0x80131904
Message=Invalid column name 'AutoCDRFiles[].[UserFileID'.
Source=.Net SqlClient Data Provider
StackTrace:
<Cannot evaluate the exception stack trace>
I'd be grateful for a reply as I really wish to move on from this issue.
Let's go with test #2 as its a 1:1 relationship a leftjoin should be used (its way faster than an Mjoin).
You are currently getting:
Which suggests that the field name on the client-side for the upload is not the same as what you have on the server-side:
From the other posts in your thread above, it looks like you might have array syntax in the field name (
fields.name
) but without being able to see your Javascript I can't say for sure.So I's say go to test #2 and check that the field name matches the field that you've attached the
Upload
to on the server-side.Regards,
Allan
Hi
I posted the code for js and the field name in "Posts: 183 Questions: 31 Answers: 2 2:13PM":
If I put name: 'AutoCDRFiles.UserFileID', instead of name: 'AutoCDRFiles[].UserFileID' to match the server side editor.Field(new Field("AutoCDRFiles.UserFileID"), I get:
System.ArgumentException
HResult=0x80070057
Message=No mapping exists from object type System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] to a known managed provider native type.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
And if I use AutoCDRFiles[].UserFileID in server and client js I get:
System.Data.SqlClient.SqlException
HResult=0x80131904
Message=Invalid column name 'AutoCDRFiles[].[UserFileID'.
Source=.Net SqlClient Data Provider
StackTrace:
<Cannot evaluate the exception stack trace>
Thanks for the clarification - I'd assumed that the Javascript there was for the Mjoin test. As I say, don't use the array syntax in the field name - use
AutoCDRFiles.UserFileID
- it has to match the server-side. I also am assuming that you've removed the Mjoin completely from the server-side code (which I'm not certain is the case given that your last post above doesn't just give an 'unknown upload field name' error.Could you show me the Javascript code and C# controller that you have with those changes so I'm fully up to date please?
For reference, this is the file upload example and this is the C# controller for it (available in the demo package):
It sounds like you are basically trying to achieve the same thing.
Allan
Yes, I have removed all refs to MJoin. Will post code in a moment. Thanks.
JS:
Server:
Can you change:
To be:
please? As you noted before its 1:1 so it shouldn't use the
many
uploader.Allan
Hi
I think there might be some confusion on my part. As I indicated in this thread it works fine with upload. I need to upload multiple files and each file has one entry in autocdrfiles and one entry in userfiles tables. I thought that was what was meant with one-to-one.
So it seems I do need an MJoin? As test #1 above indicates the upload works and but I get only one entry in autocdrfiles table no matter how many files I try to upload and that entry has no id in its userfileid field. Can you help? Thanks as ever.
Okay, yup, let's both get on the same page before we mess around with much more code!
You are using:
which means the Editor is editing the
AutoCDRFiles
table. You note above that this table has 1:1 with theUserFiles
table.I'm not clear on the multiple files aspect. Every entry in
AutoCDRFiles
will be represented by a single row in a DataTable. If you wanted multiple grouped together you'd need a grouping row in a separate database table.Allan
"The Editor is editing the AutoCDRFiles table"
Yes, that is correct.
"I'm not clear on the multiple files aspect"
The editor is jus taking many/multiple upload files
"Every entry in AutoCDRFiles will be represented by a single row in a DataTable."
Yes, that is correct.
I'm not quite understanding that - sorry if I'm being denser than normal here!
If you have each row in the
AutoCDRFiles
table shown as a row in the DataTable and you have a 1:1 relationship for the files, then where would the multiple files upload come into play?Are you looking to have a create form that can accept multiple files for upload ins a single go and that would create multiple rows in the
AutoCDRFiles
table? If so, I'm afraid that's not a feature that Editor supports at the moment. One "Create" view === one row in the database is how it works.Allan
Are you looking to have a create form that can accept multiple files for upload ins a single go and that would create multiple rows in the AutoCDRFiles table?
Yes.
Each uploaded file would have a row in AutoCDRFiles.
Is that likely to be supported? If so do you have a timescale?
I use a table (userfiles) to keep basic and common parameters to do with the users' uploaded files such as the name, path, size of files. To have to use your model means I will have to move all the disperate fields that I currently use in all my tables that deal with uploaded files to that table. That does not make a lot of sense.
Ah okay - that's why I wasn't getting it before. I'm afraid that this is not a feature that is on our roadmap since its the first time its come up!
It is possible to use
create()
to create multiple new rows at once, but that wouldn't work for multiple images since that is embedded into the form - i.e. if we went that way, each new row would all have the same image values!I agree - it doesn't. I'm not sure why you would need to move the various fields?
Allan
"I agree - it doesn't. I'm not sure why you would need to move the various fields?"
Because one single row field in a table like autocdrfiles cannot hold data for each individual uploaded file.
Right - but isn't that the point of having a central table for storing file meta information? Any other table that needs to reference a file can just use a left join link to the central files table, which then has the general file information such as extension, size, etc.
That way any information that is specific to the host table is held in the host table while generic file information is held in the files table.
That is the pattern that this example uses.
Allan
AutoCDRFile does not hold file meta information. The files are analysed by the programme and hold other fields specific to those tasks (ie different from meta info about the file), such as the scan date, if the scan was successful, the scan type,...).
"Any other table that needs to reference a file can just use a left join link to the central files table"
This would presuppose, again, that I would have to move all the fields about the scan to that files table when that files table should only hold meta info about the file and nothing else.