w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Is it possible to create model of a table from a given table of database in django model
I don't think you can tell inspectdb to generate code only for a certain table. You can just use inspectdb for all tables, and then only use the code generated for the table you want. The modelname usually is the CamelCased version of your underscored_table_name.

Categories : Django

In Umbraco 6.1.1 MVC 4, how can I do a form post back to a surface controller using a model that inherits from Umbraco's RenderModel?
Ok, I've had no responses to this question but am now in a position to answer it myself. Maybe it was a fundamental oversight, but not that obvious imho, and information on the Umbraco forum etc about inheriting from RenderModel is fairly limited. Essentially the answer, as was my first instinct, is to solve the original exception "No parameterless constructor defined for this object" by providing a paramaterless constructor. The difficulty is working out what to put inside the parameterless constructor for my model, since it inherits from the Umbraco RenderModel which requires an IPublishedContent instance passed to it's constructor. Luckily while browsing around I happened across this post on the Umbraco forum: http://our.umbraco.org/forum/developers/api-questions/40754-Getting-Curre

Categories : Asp Net Mvc

HTTP GET to return custom model with data from external database with Umbraco MVC Surface Controller
There are a lot of questions about this and the best place to look for an authoritative approach is the Umbraco MVC documentation. However, yes you will find, if you use Html.BeginUmbracoForm(...) you will be forced into a HttpPost action. With this kind of functionality (a search form), I usually build the form manually with a GET method and have it submit a querystring to a specific node URL. <form action="@Model.Content.Url"> ... </form> On that page I include an @Html.Action("SearchResults", "TyresSearch") which itself has a model that maps to the keys in the querystring: [ChildAction] public ActionResult(TyreSearchModel model){ // Find results TyreSearchResultModel results = new Wheels.BDL.TyreBDL().GetAllTyres(); // Filter results based on submitted mo

Categories : Asp Net Mvc

How do I modify an existing database table (add/remove columns) with PetaPOCO (Umbraco 6, MVC)
If you are using PetaPoco, you could use the db.Execute("alter table ...") but then you would need to have sufficient access rights to execute a DDL statement like that. Also I would run this within a PetaPoco transaction too, as it's good practice. Finally, if you were running this at Application_Start (which is fine) you would need to perform a check to ensure that the column didn't already exist.

Categories : C#

NullPointerException: Unable to create the container entity manager factory for the org.jbpm.persistence.jpa persistence unit
I was able to fix this error by setting hibernate.temp.use_jdbc_metadata_defaults to false. I'm not sure from the excerpts you posted where you would set it. For me it was the Spring config of the persistence unit.

Categories : Xml

How to configure RestKit for Core Data persistence?
Since RestKit relies on CoreData, you need to save your ManagedObjectContext in order to persist the data. I'm not sure what version you are on, but I saved the data like this: [[RKObjectManager sharedManager].objectStore.managedObjectContextForCurrentThread save:nil]; Put it inside objectLoaderDidFinishLoading:(RKObjectLoader*)objectLoader, and your objects should be saved.

Categories : IOS

How to model database where different users/roles are in a project table, while all of them have to belong to user table?
I see three tables: USER, GROUP, and ROLE. Users would be assigned to groups, and groups given roles. I think you need three, not one. And cardinality matters: I can see where a USER could be assigned to many GROUPS; a GROUP could have many USERS; a ROLE could be assigned to several GROUPS; and a GROUP could have many ROLES. There are many to many JOIN tables as well: USER <-> USER_GROUP <-> GROUP <-> GROUP_ROLE <-> ROLE This is normalized - nothing is repeated this way. USER, GROUP, and ROLE have primary keys. The JOIN table primary key is a composite of the two IDs in each row.

Categories : PHP

Persistence model vs. view model
Where they should not be separated: when they match exactly, just as in your example. Where they should be separated: when they don't match. For example, let's say you want to display a table containing, for each row: an employee name the name of his department the number of projects he's involved in That doesn't match with any persistence model entity, because in the persistence model, you'll have an Employee, with a ManyToOne association with a Department, and a ManyToMany association with Project. To load the data displayed in the table, you'll use an ad-hoc query which will load the required data from these three entities, using joins.

Categories : Java

why does set and get method in java persistence model should have the same name?
Not necessarily. Docs just recommending that format: This class(bean) uses standard JavaBean naming conventions for property setter and setter methods, as well as private visibility for the fields. Although this is the recommended design, it is not required. Hibernate can also access fields directly, the benefit of accessor methods is robustness for re factoring. My possible reason's to follow that format: 1)First of all Readability of your code. 2)Secondly,no one provide a name getCompanyName() to get username :)

Categories : Java

How to create table in mysql database with foreign key which is primary key of another table?
You can do it like follows : CREATE TABLE person ( id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, name CHAR(60) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE shirt ( id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, style ENUM('t-shirt', 'polo', 'dress') NOT NULL, color ENUM('red', 'blue', 'orange', 'white', 'black') NOT NULL, owner SMALLINT UNSIGNED NOT NULL REFERENCES person(id), PRIMARY KEY (id) ); I hope you understand the create table code. owner in the shirt table is the foreign key referencing id from the person table

Categories : Mysql

EF 5.0 (Database-First Model) not working on one table
After a deeper research I was able to find and fix the problem thanks to a reply by BRian Rogers @ Code First vs. Database First. If you are approaching Database or Model First the the connection string must have a metadata, otherwise EF interprets this as Code First approach. As I was calling the library holding EF objects from a web site, the web.config's connectionstring was a plaing database connection. <add name="EmmContext" connectionString="Data Source=.;Initial Catalog=GPMM;Persist Security Info=True;User ID=********;Pwd=******" providerName="System.Data.SqlClient"/> After changing it to <add name="EmmContext" connectionString="metadata=res://*/DAL.DBModel.csdl|res://*/DAL.DBModel.ssdl|res://*/DAL.DBModel.msl;provider=System.Data.SqlClient;provider connection string

Categories : Entity Framework

Umbraco MVC Implementation - View does not depend on Umbraco implementations
No you can't. Simply because all requests pass through a single action. In order to retrieve a path to a CMS-managed page, you need to use the node/content traversal the @Model provides. See here for more details on this. Edit To clarify, the author of the article is suggesting that the Umbraco implementation should be more in line with a traditional MVC implementation with little or no logic in the views. Therefore, any querying of node data should happen prior to the view (e.g. in the Mappers). So this is where you would have to retrieve the links. Umbraco's default MVC implementation forces all requests to go via a single action on a single controller. The author's implementation allows the requests to be shared across one controller per document type - which is better IMO. But it st

Categories : Asp Net Mvc

EF pluralize table's name on generating database from model
Just override the OnModelCreating method and remove that “PluralizingTableNameConvention” convention. So you are telling Entity Framework not to pluralise table names, simply add Updated protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); } It will remove the Pluralising convention that is by default attached to all model builders Also you need to add a namespace System.Data.Entity.ModelConfiguration.Conventions; Hope it will help

Categories : SQL

Repopulate Database with table generated from model
Can you connect to the DB as a user with sufficient permissions to create databases? You could log in as that user in SSMS and create the table with the appropriate columns etc. Then the table exists, and migrations can find it.

Categories : Asp Net

Core Data Migration: Do I Need a new Mapping Model for each new Model Version I Add?
Depending on your model changes, you may use "The Default Migration Process". When calling addPersistentStoreWithType:configuration:URL:options:error:, use the flag NSMigratePersistentStoresAutomaticallyOption. Also, I'm sure that unfortunately you need one mapping model for each possible migration. If you have 3 models, you'll have to implement: 1 to 3 and 2 to 3. Core Data is not smart enough to do the intermediate steps automatically :(

Categories : Iphone

How to create Inherited Member-Type in Umbraco 6.X?
Member objects do not quite work like that in Umbraco. You can not inherited member objects in the same way that you can inherit document types or media types. I would simply create two independent user types here with the properties you require. If you desperately want the inheritance, you could implement your own membership provider or extension to the API, but even then the inheritance would not be visible in Umbraco, only at the code level. In Umbraco the member types would still appear as independent objects. So it seems like little gain.

Categories : Asp Net

How to create html table from model class
If you want to iterate through your model and create your table, first of all change the @model of your view like this: @model IEnumerable<myPrj.Models.EntityName> Then, you should change your action method to supply model items to your view: public ActionResult Index() { return View(db.EntityNames.ToList()); } and finally, iterate your model and create your table: <table id="tblNews"> <tr> <th> @Html.DisplayNameFor(model => model.Property1) </th> // ... <th> @Html.DisplayNameFor(model => model.Propertyn) </th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.Property1) </td> // ... <t

Categories : C#

Umbraco - error when using umbraco.library:NiceUrl(...)
Ok I found a solution: I added an extra check to this part: <!-- Return the url --> <xsl:if test="$i = $max"> <xsl:if test="$id != '' "> <xsl:value-of select="umbraco.library:NiceUrl($id)" /> </xsl:if> </xsl:if> this fixed my problem.

Categories : Xslt

Umbraco MediaService / Umbraco MediaItem not saving
To Save media, I found this method with MediaService. However, I think it's possible another method more refined [HttpPost] public JsonResult Upload(HttpPostedFileBase file) { IMedia mimage; // Create the media item mimage = _mediaService.CreateMedia(file.FileName, <parentId>, Constants.Conventions.MediaTypes.Image); mimage.SetValue(Constants.Conventions.Media.File, file); _mediaService.Save(mimage); return Json(new { success = true}); }

Categories : C#

How to update only one table for model from database with Entity Framework?
The EDMX file is an XML file that is a combination of 3 different parts that make up the whole thing. If you right-click on your EDMX file and choose "Open with... XML Editor" you'll see the 3 different sections: <edmx:ConceptualModels> <edmx:StorageModels> <edmx:Mappings> These sections can be edited manually, at your own risk! :-) That way you can modify only what you need to. Note that it's also possible to generate CSDL, SSDL & MSL files rather than having them embedded in the binary file, by changing the "Meta Artifact Processing" property of your model to "Copy to Output Directory". If you don't want to do this manually, there's the Huagati DBML/EDMX tool, it is free and you can download it from huagati official site or from visual studio gallery, which is

Categories : Entity Framework

Grails - Hibernate - cannot create model class / table
Move your domain class to grails-app/domain and change it to this: class User { String email static mapping = { datasource 'system' } static constraints = { email nullable: false } } 11 lines vs. 31 lines. Groovy.

Categories : Java

How to create a view model object that gets information from multiple database tables
If you have created an entity framework model from your database schema you should have: An AccountDefinition class with an AccountDefinition.SDOrganization reference navigation property because the relationship between the two is apparently one-to-one A SDOrganization.AaaPostAddresses collection navigation property because the relationship is many-to-many. The SDOrgPostalAddr table should not appear as model entity because it is only the many-to-many link table With this model and changing your view model to... public class CustomerDetails { public AccountDefinition AccountDefinition {get; set;} public SDOrganization SDOrganization {get; set;} public ICollection<AaaPostalAddress> AaaPostalAddresses { get; set; } } ...you should be able to get the result using: v

Categories : C#

saving many to many form field values in to database table(model)
So, if you read the documentation on ModelForms, you will notice that they are equipped with a save() method, which already provides the functionality you want. You can use if form.is_valid(): form.save() or, if you want to add more values to the model, you can if form.is_valid(): instance = form.save(commit=False) instance.custom_field = custom_value instance.save()

Categories : Django

Embedded form persistence : get or create
Create your own getOrCreate() method and call it inside your listener. See this post Symfony2 doctrine FindOneOrCreate Another possibility would be the data transformers. http://symfony.com/doc/current/cookbook/form/data_transformers.html

Categories : Symfony2

build a org.eclipse.persistence.queries.ReportQuery from a javax.persistence.Query
How are you executing the ReportQuery? You need to call Session.executeQuery(query, arguments) and pass a List of the arguments (order the same as query.getArguments(). You can probably also use the JpaEntityManager createQuery(DatabaseQuery) API to convert the ReportQuery back to a JPA Query, then you can just set the parameter the JPA way.

Categories : Java

Sorting a Rails database table by a column in an associated model with additional scoping
You don't actually say what "doesn't work" means in this context. I would guess that it either means you get an error message or that the Projects aren't sorted the way you expect. If it's an error message, you should include it with your question, but the first thing I'd do in your place is probably to start using the Rails conventions for naming and referring to things. If your associated class is UserDefinedField, Rails is going to expect the table to be named user_defined_fields and the association to be specified as has_many :user_defined_fields. It also expects fields to be in snake case (attach_to_id, not attachtoid), but aside from having to specify every foreign key everywhere, that probably won't cause errors. Looking at your code, I would expect Rails to be complaining about th

Categories : Ruby On Rails

persistence exception on database connection using glassfish
My first guess is that the connection URL in the data source definition is not quite right because "No database selected Error Code: 1046" is a MySQL error. You do not need to configure the data source in persistence.xml if you have already defined a data source in your application server (which is the common way). Can you post the data source definition from your $GLASSFISH_HOME/glassfish/domains/$GLASSFISH_DOMAIN/config/domain.xml? This is an example persistence.xml I took from an project of mine (more or less from the Netbeans template) that might help you: <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persist

Categories : Mysql

Error creating bean with name 'entityManagerFactory' -> Cannot parse persistence unit from class path resource [META-INF/persistence.xml]
Firstly, java compiler will not validate the existence of persistence.xml during compile time. The error only happen at runtime. Stack trace you're getting is pretty clear, your program could not locate persistence.xml on classpath. The location of persistence.xml within your jar has to be: META-INF/persistence.xml, or if it's war: WEB-INF/classes/META-INF/persistence.xml

Categories : Java

Database error: no such table: auth_user. Extending AbstractUser and using model to register on admin
So deleted all the work I had done with this and moved on with the standard user so that I could make progress. Then one day I went back to it and managed to get it working in an hour. I'll post the code for reference but I can't really pin point what made the difference. I do know that the creation forms and stuff were not necessary. models.py class PropaUser(AbstractUser): uuid = UUIDField(auto=True) admin.py from django.contrib import admin from login.models import PropaUser admin.site.register(PropaUser) settings.py AUTH_USER_MODEL = "login.PropaUser" other models.py class Word(models.Model): user = models.ManyToManyField(settings.AUTH_USER_MODEL) deck = models.ManyToManyField(Deck) word = models.CharField(max_length=100) def __unicode__(self): # Pyt

Categories : Django

Core Plot and Xcode 5 Compile Error: "Implicit conversion from enumeration type 'enum UILineBreakMode'
That should only be a warning, unless you've turned on -Werror (not a bad idea). Regardless, if you looked at the autocomplete for "NSLineBreak," which the error implies you should, you would see NSLineBreakByWordWrapping.

Categories : IOS

create a div dynamically for every row in database table ASP.Net
This scenario can be solved in many different ways. The general approach though is some sort of data binding. If you're doing web forms I would look into the Repeater control, which will offer good template based data binding. A less elegant way is to just loop out some dynamic html.

Categories : Asp Net

Could not locate Razor Host Factory type: umbraco.MacroEngines.RazorUmbracoFactory, umbraco.MacroEngines
If you are trying to host the blogengine site within a virtual directory of the Umbraco site, then you will have to amend the blogengine web.config to "remove" all the Umbraco-specific handlers and modules, as these will be inherited by the blogengine application, causing this exception because the application can't find the relevant DLLs in its bin folder. I recently had a similar problem and I have posted the web.config I used in the virtual directory below. Mine was a very simple web application, so obviously this will not work by itself in your blogengine app. You will need to add the relevant parts into your web.config file. Also, this was for a v6 Umbraco install in IIS7.5, so you may have to experiment a little. <?xml version="1.0"?> <configuration> <configSecti

Categories : Iis

How to access multiple database schemas from single persistence unit?
If you are using Oracle and you have SCHEMA_1 and SCHEMA_2 and you can define synonyms: As SCHEMA_2, grant the appropriate privileges to SCHEMA_1 Define synonyms in SCHEMA_1 for the tables in SCHEMA_2 Now in SCHEMA_1 you should be able to use SCHEMA_2 tables as if they were there

Categories : Java

Rails controller create action difference between Model.new and Model.create
The Model.new method creates a nil model instance and the Model.create method additionally tries to save it to the database directly. Model.create method creates an object (or multiple objects) and saves it to the database, if validations pass. The resulting object is returned whether the object was saved successfully to the database or not. object = Model.create does not need any object.save method to save the values in database. In Model.new method, new objects can be instantiated as either empty (pass no construction parameter) In Model.new(params[:params]) pre-set with attributes but not yet saved in DB(pass a hash with key names matching the associated table column names). After object = Model.new, we need to save the object by object.save

Categories : Ruby On Rails

create table in database using EF from our applictaion Dynamically
Depends on what you understand by dynamic here. Changing the runtime version of the Context isnt possible. Generating, compiling, loading NEW code is. So a new context, and POCO code can be declared. Compiled and loaded. All controlled by a piece of running code. However, the ongoing lifecycle gets complicated. The use of code first migrations becomes tricky. How to manage chnages to extensions in Prod. How to merge ongoing dev and prod. Managing the mapping in Fluent API in generated code is awful. You cant do it all in Attributes. The context backflips and automated migrations nightmares have cost me many a night. Dealing with main build natural extensions and production/localised implementation extension gets VERY hard. You need to make sure they are incorporated back into the b

Categories : Entity Framework

Create Query with doctrine 1.2 in which table name needs to be from database
Other way of Fracsi's solution: $item = Doctrine::getTable("StaticPage")->findOneById($id); if($item instanceof StaticPage) { $item->setPublished(true); $item->save(); } Always use your model/ORM. There are few cases in which Doctrine can't build the correct query syntax and you have to write sql on your own.

Categories : PHP

Postgresql - Create Database & Table dynamically
Solution: // 1. Connect to server to create database: const string connStr = "Server=localhost;Port=5432;User Id=postgres;Password=enter;"; // 2. Connect to server to create table: const string connStr2 = "Server=localhost;Port=5432;User Id=postgres;Password=enter;Database=testDb"; var m_conn = new NpgsqlConnection(connStr); // db connction var m_conn2 = new NpgsqlConnection(connStr2); // table connection // creating a database in Postgresql m_createdb_cmd = new NpgsqlCommand("CREATE DATABASE IF NOT EXISTS "testDb" " + "WITH OWNER = "postgres" " + "ENCODING = 'UTF8' " + "CONNECTION LIMIT = -1;", m_conn); // creating a table in Postgresql m_

Categories : C#

How to create dynamic database table in SQLite
Android allows you to execute arbitrary SQL strings. Construct a SQL strings from your UI and then input the string into a command similar to db.execute(string). Reference

Categories : Android

Database Schema - Create one large table or many?
I think it's hard to anticipate the actual performance of one vs the other since it's dependent on so many things. Several considerations: How important is the difference between entities? If you find yourself often selecting just one type of entity per query then the normalized solution is likely faster. If you have queries that select on other things than the shared columns, like: entity_a with entity_c IN(something) you'll want an index on the entity_c column. entity_c is very large. If it gets updated a lot, and queried very rarely then that's a cause for concern if you're going for the de-normalized version. If you're doing a lot of JOINs I'm pretty sure the normalized form is faster. My advice would be: use the normalized form. If you're seeing performance issues you could look

Categories : PHP

Visual Studio for Web 2012 - Cant create table in SQL database
With SQL Server 2012, you also need to install the SQL Server Data Tools update: http://msdn.microsoft.com/en-us/jj650015

Categories : Visual Studio 2012



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.