New to Raven. I have an MVC page that saves data to a Raven document. I am able to save all fields as expected. I have noticed the Id (field/attribute of the table/class structure in my project) is null and it does not get saved into the document. There is a Raven system generated Id in the title of the document (like DocName/123 etc...). How can I get that DocName/123 or 123 or some other auto generated Id field save into the raven document? Please help..Thank you
Raven will Automatically generate the Id if it is not specified. If you don't want Raven to generate this key then you need to specify public string Id {get; set;}
property in your class.`
Related
Grails will create an id and a version columns from a domain class automatically. I want to use my own column for the primary key. So, I follow the doc to change the mapping.
class book {
String isbn
static mapping = {
id generator: 'assigned', name: 'isbn'
}
}
So far so good. The isbn column is now the primary key.
I use generate-all to create the view and controller. However, the data binding won't work anymore.
Create and Save work no problem. It binds a book to the view. I can add a new book to the database no problem.
def create() {
respond new Book(params)
}
def save(Book book) {
if (book == null) {
notFound()
return
}
...
}
But the Update action does not bind. book is null after I click the Update button from the Edit view.
def update(Book book) {
if (book == null) {
notFound()
return
}
...
}
The codes generated by generate-all in the Save and Update actions are the same. I don't understand why it will bind the book to the Save action but not to Update action.
Would you show me the problem please?
Many Thanks!
I think I figure it out. When I bind an object to a view, Grails is hardcoded to look for the id property. It has to be spelled "id". If there is no "id" property in the domain class, Grails will not bind.
The way I figure this out is to look at the actual HTML generated by the server.
If there is an id property bind to the view, I see the HTML has the ../controller/action/id link.
If the id property is missing, the HTML link is just ../controller/index
I am new to Grails. So, I guess in order for the binding to work, I need to have an id property for Grails to put in the link.
I think this is a REST call. I don't know what REST is though.
So, I will try to add an dummy id property to my Book domain class to see if Grails will take the bait. I will set up the domain so Grails won't generate the id column in the database table. The id property is used locally only. No need to save it to the database.
class book {
String isbn
String id
static mapping = {
id generator: 'assigned', name: 'isbn'
}
}
I will copy the isbn value to the id property. I am not sure if this will work or not. I hope Grails will generate the link in the view with the isbn string in the id property instead of the default integer id value.
../controller/action/978-3-16-148410-0
A client of mine came with the following demand:
Add the option to upload a file to the server
Save the file id as a guid in database
I followed this answer- so the file upload is working(to a specific location on the server)
http://stackoverflow.com/questions/5193842/file-upload-asp-net-mvc-3-0
What i don't familiar with is his second demand:
Save the file id as a guid in database
What does it mean?
Why does the file need a guid id in the database?
What should I do in extra to the post I linked to?(security check, extension check?)
guid = globaly unique identifier.
Why does a file need a guid in database ? well because its your client's requirement its not required by the database.
And finally how to do it? is simple when you will be saving a filename to database generate a guid and save it to the database you can generate a guid like this Guid id = Guid.NewGuid(); and you can create a separate column in the database for saving file's guids.
I want to add image uploader to my web form in Acumatica. But I hardly imagine what fields should be presented in DAC and in DB. Another question which I have is how to manage storage for images.
Is it possible to store them in db, cloud, file system?
ImageUploader uses the files attached to an entity plus (optionally) a string field that can store the selected file name (screen title + (entity key values) + \ file name, to be precise). Since these are just regular attached files the usual storage options apply (i.e. DB or whatever storage provider you use). The files that are displayed have extensions marked as "Image" in file upload preferences.
There's nothing special about the filename field really. You need add a string to your DAC:
public partial class YourEntity : PX.Data.IBqlTable {
...
public abstract class filename : PX.Data.IBqlField{}
[PXDBString(255, IsUnicode = true)]
public virtual string Filename { get; set; }
...
}
add a corresponding field to your database:
create table "YourEntity" (
...
"Filename" nvarchar(255) null,
...
)
and specify that field name in aspx page when adding a control:
<px:PXImageUploader ID="controlField" runat="server" DataField="Filename" ...
The user will be able to pick the selected image by on-screen arrows (or Ctrl - arrow keyboard combo) from all the attached images.
It's possible not to use the filename field at all. In that case the control will show the first attached image, and the user will be able to scroll through all the attached images.
I want to retrieve data of particular user from two different tables such as "Organizations" and "SystemUsers" in which the company details are stored in "Organizations" & his personal info. is stored in "Systemusers" like emailid,password etc..
But what my requirement is I want to retrieve that particular user organization details as well as personal info like emailid, using entityframework in asp.net mvc. Can anyone suggest me the query to do this.
Table: Organizations
public string CompanyName {get; set;}
Table : Systemusers
public string Email {get; set;}
So, I want to retrieve the user company details as well as personal details from two tables so as to display them in search form.Can anyone suggest me query for this????
going by your description and lack of code im assuming that every user will have 0 or 1 organization.
so 1. you will have to make a one to 0 or 1 relation between user and organization then a simple query on the SystemUser table will retrieve the Users personal info and because now in this table you will have a foreign key (assuming name to be Organization) you can retrieve the organiation info using .Organization property of the retrieved SystemUser
Hey, sorry for my bad english...
Using EF4 code-only, I have created some POCO classes and my database was generated from that. All worked fine, I inserted some data on the tables but now I need to create a new property on one of my classes. If i just create it, the application give me the exception:
{"The model backing the 'TestContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the RecreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data."}
I tried to create manually the field on the table, but it is still complaining... does someone know if there is a way and if so how can I manually update the database schema (i don't want to recreate it because i already have data) to match the model?
It should work if you make sure that your new column match exactly your new property.
For example, if you add a property NewProp
public class MyEntity
{
[Key]
public int Id;
public string PropA;
public int PropB;
public int NewProp;
}
then in your database table MyEntities, you would add a column NewProp of type int not null.
What you can do to check if the column you add is correct, is to rename your database, then let Code-First recreate the database and see what's different between the original and new databases.
EF generates partial classes. So you can add new properties(fields) in another partial class.