Search Results

Search found 6630 results on 266 pages for 'cname record'.

Page 49/266 | < Previous Page | 45 46 47 48 49 50 51 52 53 54 55 56  | Next Page >

  • Add child to existing parent record in entity framework.

    - by Shawn Mclean
    My relationship between the parent and child is that they are connected by an edge. It is similiar to a directed graph structure. DAL: public void SaveResource(Resource resource) { context.AddToResources(resource); //Should also add children. context.SaveChanges(); } public Resource GetResource(int resourceId) { var resource = (from r in context.Resources .Include("ToEdges").Include("FromEdges") where r.ResourceId == resourceId select r).SingleOrDefault(); return resource; } Service: public void AddChildResource(int parentResourceId, Resource childResource) { Resource parentResource = repository.GetResource(parentResourceId); ResourceEdge inEdge = new ResourceEdge(); inEdge.ToResource = childResource; parentResource.ToEdges.Add(inEdge); repository.SaveResource(parentResource); } Error: An object with the same key already exists in the ObjectStateManager. The existing object is in the Unchanged state. An object can only be added to the ObjectStateManager again if it is in the added state. Image: I have been told this is the sequence in submitting a child to an already existing parent: Get parent - Attach Child to parent - submit parent. That is the sequence I used. The code above is extracted from an ASP.NET MVC 2 application using the repository pattern.

    Read the article

  • How do I combine grouped nodes?

    - by LOlliffe
    Using the XSL: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:output method="xml"/> <xsl:template match="/"> <records> <record> <!-- Group record by bigID, for further processing --> <xsl:for-each-group select="records/record" group-by="bigID"> <xsl:sort select="bigID"/> <xsl:for-each select="current-group()"> <!-- Create new combined record --> <bigID> <!-- <xsl:value-of select="."/> --> <xsl:for-each select="."> <xsl:value-of select="bigID"/> </xsl:for-each> </bigID> <text> <xsl:value-of select="text"/> </text> </xsl:for-each> </xsl:for-each-group> </record> </records> </xsl:template> I'm trying to change: <?xml version="1.0" encoding="UTF-8"?> <records> <record> <bigID>123</bigID> <text>Contains text for 123</text> <bigID>456</bigID> <text>Some 456 text</text> <bigID>123</bigID> <text>More 123 text</text> <bigID>123</bigID> <text>Yet more 123 text</text> </record> into: <?xml version="1.0" encoding="UTF-8"?> <records> <record> <bigID>123</bigID> <text>Contains text for 123</text> <text>More 123 text</text> <text>Yet more 123 text</text> </bigID> <bigID>456 <text>Some 456 text</text> </bigID> </record> Right now, I'm just listing the grouped <bigIDs, individually. I'm missing the step after grouping, where I combine the grouped <bigID nodes. My suspicion is that I need to use the "key" function somehow, but I'm not sure. Thanks for any help.

    Read the article

  • How to return all records and whether a related record exists?

    - by David Glenn
    Using Entity Framework 4 CTP5 I have a basic model and a basic DbContext that works public class Customer { public int CustomerId { get; set; } public int Name { get; set; } //... public ICollection<Address> Addresses { get; set; } public bool HasAddress { get { return Addresses.Count > 0; } } } public class Address { public int AddressId { get; set; } public string StreetLine1 { get; set; } //.... public Customer Customer { get; set; } } How can I query my DbContext to return all customers and whether they have an address? A customer can have multiple addresses and I don't want to return all the addresses for each customer when I am only interested in whether they have an address or not. I use context.Customers.Include(c => c.Addresses) but that returns all addresses for each customer

    Read the article

  • Which event handler to use to record leaving page - onunload or onbeforeunload?

    - by symcbean
    Hi all, Having not any answers to my previous questions about using javascript to measure page turn times, I'm going to start writing my own code (!). To measure the length of tie it takes, I'm proposing dropping a cookie containing a timestamp when the user browses away from a page, then in a subsequent page, comparing that time with 'now' and sending back a request to a URL which will log the interval. It seems that there are 2 possible handlers I could associate the first block of code with - the onunload() handler or the onbeforeunload()? It's more important that it fail silently on browsers with no/broken support for the handler, than it be portable across every possible browser. Any pointers? Gotchas? TIA C.

    Read the article

  • Rails - eager load the number of associated records, but not the record themselves.

    - by Max Williams
    I have a page that's taking ages to render out. Half of the time (3 seconds) is spent on a .find call which has a bunch of eager-loaded associations. All i actually need is the number of associated records in each case, to display in a table: i don't need the actual records themselves. Is there a way to just eager load the count? Here's a simplified example: @subjects = Subject.find(:all, :include => [:questions]) In my table, for each row (ie each subject) i just show the values of the subject fields and the number of associated questions for each subject. Can i optimise the above find call to suit these requirements? I thought about using a group field but my full call has a few different associations included, with some second-order associations, so i don't think group by will work. @subjects = Subject.find(:all, :include => [{:questions => :tags}, {:quizzes => :tags}], :order => "subjects.name") :tags in this case is a second-order association, via taggings. Here's my associations in case it's not clear what's going on. Subject has_many :questions has_many :quizzes Question belongs_to :subject has_many :taggings has_many :tags, :through => :taggings Quiz belongs_to :subject has_many :taggings has_many :tags, :through => :taggings Grateful for any advice - max

    Read the article

  • Best way to get record counts grouped by month, adjusted for time zone, using SQL or LINQ to SQL

    - by Jeff Putz
    I'm looking for the most efficient way to suck out a series of monthly counts of records in my database, but adjusting for time zone, since the times are actually stored as UTC. I would like my result set to be a series of objects that include month, year and count. I have LINQ to SQL objects that looks something like this: public class MyRecord { public int ID { get; set; } public DateTime TimeStamp { get; set; } public string Data { get; set; } } I'm not opposed to using straight SQL, but LINQ to SQL would at least keep the code a lot more clean. The time zone adjustment is available as an integer (-5, for example). Again, the result set what I'm looking for is objects containing the month, year and count, all integers. Any suggestions? I can think of several ways to do it straight, but not with a time zone adjustment.

    Read the article

  • How can I override the attribute assignment in an active record object?

    - by ryeguy
    I know you can do this with virtual attributes, but what if the column actually exists? For example, my model has a raw_topic column. When raw_topic is set, I want artist and song_title to be set based off of raw_topic's contents. Ideally, I'd like to override the raw_topic= method, but rails doesn't seem to like that. What's the proper way of doing this? Is a callback the only way?

    Read the article

  • How can I update a record using a correlated subquery?

    - by froadie
    I have a function that accepts one parameter and returns a table/resultset. I want to set a field in a table to the first result of that recordset, passing in one of the table's other fields as the parameter. If that's too complicated in words, the query looks something like this: UPDATE myTable SET myField = (SELECT TOP 1 myFunctionField FROM fn_doSomething(myOtherField) WHERE someCondition = 'something') WHERE someOtherCondition = 'somethingElse' In this example, myField and myOtherField are fields in myTable, and myFunctionField is a field return by fn_doSomething. This seems logical to me, but I'm getting the following strange error: 'myOtherField' is not a recognized OPTIMIZER LOCK HINTS option. Any idea what I'm doing wrong, and how I can accomplish this? *UPDATE: * Based on Anil Soman's answer, I realized that the function is expecting a string parameter and the field being passed is an integer. I'm not sure if this should be a problem as an explicit call to the function using an integer value works - e.g. fn_doSomething(12345) seems to automatically cast the number to an string. However, I tried to do an explicit cast: UPDATE myTable SET myField = (SELECT TOP 1 myFunctionField FROM fn_doSomething(CAST(myOtherField AS varchar(1000))) WHERE someCondition = 'something') WHERE someOtherCondition = 'somethingElse' Now I'm getting the following error: Line 5: Incorrect syntax near '('.

    Read the article

  • how to insert record in database with each date of month on single button click ?

    - by Mr. Goo
    I have two textbox .... textbox1 and textbox2 textbox1 == choose from date textbox2 == choose to date if user select from date in textbox1 as 01-May-2011 and in textbox2 as 30-May-2011 then all the dates from 01-MAy-2011 to 30-May-2011 will be inserted in each row of mssql2005 datatable... example. . : IN database Table1 structure ... ID Date 1 01-MAy-2011 2 02-MAy-2011 3 03-MAy-2011 4 04-MAy-2011 5 05-MAy-2011 and so on till 30-May-2011

    Read the article

  • Why getting active record error when trying to work on arrays?

    - by keruilin
    I have the following association in my User model: has_and_belongs_to_many :friends, :class_name => 'User', :foreign_key => 'friend_id' I have the following uniqueness constraint in my user_users table: UNIQUE KEY `no_duplicate_friends` (`user_id`,`friend_id`) In my code, I am retrieving a user's friends -- friends = user.friends. friends is an array. I have a scenario where I want add the user with all those friends to the friends array. Ex: friends << user_with_all_those_homies However, I get the following error: ActiveRecord::StatementInvalid: Mysql::Error: Duplicate entry '18-18' for key 'no_duplicate_friends': INSERT INTO `users_users` (`friend_id`, `user_id`) VALUES (18, 18) What gives?

    Read the article

  • Saving an active record, in what order are the associated objects saved?

    - by Bryan
    In rails, when saving an active_record object, its associated objects will be saved as well. But has_one and has_many association have different order in saving objects. I have three simplified models: class Team < ActiveRecord::Base has_many :players has_one :coach end class Player < ActiveRecord::Base belongs_to :team validates_presence_of :team_id end class Coach < ActiveRecord::Base belongs_to :team validates_presence_of :team_id end I expected that when team.save is called, team should be saved before its associated coach and players. I use the following code to test these models: t = Team.new team.coach = Coach.new team.save! team.save! returns true. But in another test: t = Team.new team.players << Player.new team.save! team.save! gives the following error: > ActiveRecord::RecordInvalid: > Validation failed: Players is invalid I figured out that team.save! saves objects in the following order: 1) players, 2) team, and 3) coach. This is why I got the error: When a player is saved, team doesn't yet have a id, so validates_presence_of :team_id fails in player. Can someone explain to me why objects are saved in this order? This seems not logical to me.

    Read the article

  • How to find all records that share the same field value as some other record?

    - by Gj
    I need to extract all records which have a field which does NOT have a unique value. I can't figure out an elegant way to do it - using annotation or some other way. I see a "value_annotate" method to the object manager but it's unclear if it's at all related. Currently I'm using the inelegant way of simple looping through all values and doing a get on the value, and if there's an exception it means it's not unique.. Thanks

    Read the article

  • My Linq to Sql Insert code seems to work fine but I don't get a record in the database

    - by Alex
    Here is my code. In the debugger, I can see that the code is running. No errors are thrown. But, when I go back to the table, no row has been inserted. What am I missing?? protected void submitButton_Click(object sender, EventArgs e) { CfdDataClassesDataContext db = new CfdDataClassesDataContext(); string sOfficeSought = officesSoughtDropDownList.SelectedValue; int iOfficeSought; Int32.TryParse(sOfficeSought, out iOfficeSought); Account act = new Account() { FirstName = firstNameTextBox.Text, MiddleName = middleNamelTextBox.Text, LastName = lastNameTextBox.Text, Suffix = suffixTextBox.Text, CampaignName = campaignNameTextBox.Text, Address1 = address1TextBox.Text, Address2 = address2TextBox.Text, TownCity = townCityTextBox.Text, State = stateTextBox.Text, ZipCode = zipTextBox.Text, Phone = phoneTextBox.Text, Fax = faxTextBox.Text, PartyAffiliation = partyAfilliatinoTextBox.Text, EmailAddress = emailTextBox.Text, BankName = bankNameTextBox.Text, BankMailingAddress = bankAddressTextBox.Text, BankTownCity = bankTownCityTextBox.Text, BankState = bankStateTextBox.Text, BankZip = bankZipTextBox.Text, TreasurerFirstName = treasurerFirstNameTextBox.Text, TreasurerMiddleName = treasurerMiddleNamelTextBox.Text, TreasurerLastName = treasurerLastNameTextBox.Text, TreasurerMailingAddress = treasurerMailingAddressTextBox.Text, TreasurerTownCity = treasurerTownCityTextBox.Text, TreasurerState = treasurerStateTextBox.Text, TreasurerZipCode = treasurerZipTextBox.Text, TreasurerPhone = treasurerPhoneTextBox.Text //OfficeSought = iOfficeSought }; act.Suffix = suffixTextBox.Text; db.SubmitChanges(); }

    Read the article

  • How to block the possibility to add the same record to a SPList?

    - by truthseeker
    Hi, Is there a possibility to block chance to add the same data to SPList? I know that two records always are different regarding the ID field. I would like to validate other custom fields added previously by me, and don't allow of adding same field's value. Can anybody tell me how to implement this? I can guess that event receivers could be the answer but I couldn't find how to add a receiver to SPList. Can anybody tel me If I'm right and what is step by step procedure to add such event receiver? I would like to know how to build it and install it using Feature file. Best Regards T.S.

    Read the article

  • How to do an additional search on archive in rails if record not found, by extending model?

    - by Nick Gorbikoff
    Hello, I was wondering if somebody knows an elegant solution to the following: Suppose I have a table that holds orders, with a bunch of data. So I'm at 1M records, and searches begin to take time. So I want to speed it up by archiving some data that is more than 3 years old - saving it into a table called orders-archive, and then purging them from the orders table. So if we need to research something or customer wants to pull older information - they still can, but 99% of the lookups are done on the orders no older than a year and a half - so there is no reason to keep looking through older data all the time. These move & purge operations can be then croned to be done on a weekly basis. I already did some tests and I know that I will slash my search times by about 4 times. So far so good, right? However I was thinking about how to implement older archival lookups and the only reasonable thing I can think of is some sort of if-else If not found in orders, do a search in orders-archive. However - I have about 20 tables that I want to archive and god knows how many searches / finds are done through out the code, that I don't want to modify. So I was wondering if there is an elegant rails-way solution to this problem, by extending a model somehow? Has anyone dealt with similar case before? Thank you.

    Read the article

  • Hibernate: getting a record but it's being updated in the database?

    - by jack
    For some reason Hibernate seems to be keeping my session open and updating the object without me explicitely invoking a save/update/saveorupdate. I guess the session is staying open and it's beeing marked as dirty. However this is not the desired behaviour, so what's the cleanest way to fix this? The issue seems to occur because I store a phone number without formatting in the database but the getter of the object returns a formatted telephone number. My flow: go to a jsp = controller = service = dao DAO getter function if(userId != 0) { return (User)dbFactory.get(User.class, userId); } return null; The service just passes it to the controller and the controller puts te User object in the request scope. I display it on my JSP page using EL.

    Read the article

  • Is it possible to use SQL XML to insert, and get output from each record?

    - by nbolton
    I would like to perform a SQL XML insert (on MSSQL), and in this case I need to insert a list of files into the DB (this is simple enough). However, there's an auto generated PK column (ID), and I need the ID for each newly created filename without performing a 2nd query. Is this possible? I guess it doesn't matter if the result is/isn't XML, but the input certainly has to be.

    Read the article

  • Active Record Associations: has_one :through? Or multiple has_one's?

    - by jmccartie
    I'm brand new to Rails, so bear with me. I have 3 models: User, Section, and Tick. Each section is created by a user. My guess with this association: class Section < ActiveRecord::Base has_one :user end Next, each user can "tick" off a section -- only once. So for each tick, I have a section_id, user_id, and timestamps. Here's where I'm stuck. Does this call for a "has_one :through" association? If so, which direction? If not, then I'm way off. Which association works here? Thanks!

    Read the article

  • Should nested attributes be automatically deleted when I delete the parent record?

    - by brad
    I'm playing around with nested forms in attributes and have a model Invoice that has_many invoice_phone_numbers. I have the following line in my invoice.rb model file accepts_nested_attributes_for :invoice_phone_numbers, :allow_destroy => true, :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } } This does what it should and I can delete invoice_phone_numbers from the form by selecting their 'delete' checkbox. But when I delete an Invoice, I have noticed that the nested invoice_phone_numbers are not also deleted. This causes problems as rails seems to reuse id numbers in the Invoice model (Should it? Does this depend on the database? I'm using SQLite3) so phone numbers from previous invoices turn up in new invoices after they have been created. Anyway, my question is should the nested attributes be deleted when I delete the parent attribute? Is there a way to make this happen automatically as part of the nesting process or do I need to deal with this in my invoice model? If so, what is the best way to do this? I would try to go about this with a before_destroy callback but want to know if this is the best way to do this. Anyway, thanks.

    Read the article

  • How does object of sub-class record information about its super-class the in a Virtual Inheritance

    - by Summer_More_More_Tea
    Hi there: I encounter this problem when tackling with virtual inheritance. I remember that in a non-virtual inheritance hierarchy, object of sub-class hold an object of its direct super-class. What about virtual inheritance? In this situation, does object of sub-class hold an object of its super-class directly or just hold a pointer pointing to an object of its super-class? By the way, why the output of the following code is: sizeof(A): 8 sizeof(B): 20 sizeof(C): 32 Code: #include <iostream> using namespace std; class A{ char k[ 3 ]; public: virtual void a(){}; }; class B : public virtual A{ char j[ 3 ]; public: virtual void b(){}; }; class C : public virtual B{ char i[ 3 ]; public: virtual void c(){}; }; int main( int argc, char *argv[] ){ cout << "sizeof(A): " << sizeof( A ) << endl; cout << "sizeof(B): " << sizeof( B ) << endl; cout << "sizeof(C): " << sizeof( C ) << endl; return 0; } Thanks in advance. Kind regards.

    Read the article

  • rails 3, active record: any way to tell how many unique values match a "x LIKE ?" query

    - by jpwynn
    I have a query to find all the phone numbers that match a partial expression such as "ends with 234" @matchingphones = Calls.find :all, :conditions => [ "(thephonenumber LIKE ?)", "%234"] The same phone number might be in the database several times, and so might be returned multiple times by this query if it matches. What I need is to know is UNIQUE phone numbers the query returns. For example if the database contains 000-111-1234 * 000-111-3333 000-111-2234 * 000-111-1234 * 000-111-4444 the existing query will return the 3 records marked with * (eg returns one phone number -1234 twice since it's in the database twice) what I need is a query that returns just once instance of each match, in this case 000-111-1234 * 000-111-2234 *

    Read the article

  • Set to null a parent record so that children are removed: howto?

    - by EugeneP
    How to delete a child row (on delete cascade ?) when setting a null value on a parent? Here's the db design. table A [id, b_id_1, b_id_2] table B [id, other fields...] b_id_1 and b_id_2 can be NULL if any of them is null, it means NO B records for corresponding FK (there are 2 of them) so (b_id_1,b_id_2) can be (null,null), (100, null), (null, 100_or_any_other_number) etc How in one SQL query both set b_id_1 or b_id_2 to null and delete all rows from B that have this id? What FK design should be applied to the 2 tables? what foreign keys should be added? A - B (FK_1: A.b_id_1 references B.id, FK_2: A.b_id_2 references B.id) and also B-A (FK_3: B.id references A.b_id_1, FK_4: B.id references A.b_id_2) ? But again, setting an A's b_id_1 or A's b_id_2 to null - will it remove any of B's records? I don't think so. So how to do that?

    Read the article

< Previous Page | 45 46 47 48 49 50 51 52 53 54 55 56  | Next Page >