So I'm have a really hard time figuring out when I should be attaching to an object and when I shouldn't be attaching to an object. First thing's first, here is a small diagram of my (very simplified) object model.
Edit: Okay, apparently I'm not allowed to post images...here you go: http://i.imgur.com/2ROFI.png
In my DAL I create a new DataContext every time I do a data-related operation. Say, for instance, I want to save a new user. In my business layer I create a new user.
var user = new User();
user.FirstName = "Bob";
user.LastName = "Smith";
user.Username = "bob.smith";
user.Password = StringUtilities.EncodePassword("MyPassword123");
user.Organization = someOrganization; // Assume that someOrganization was loaded and it's data context has been garbage collected.
Now I want to go save this user.
var userRepository = new RepositoryFactory.GetRepository<UserRepository>();
userRepository.Save(user);
Neato! Here is my save logic:
public void Save(User user)
{
if (!DataContext.Users.Contains(user))
{
user.Id = Guid.NewGuid();
user.CreatedDate = DateTime.Now;
user.Disabled = false;
//DataContext.Organizations.Attach(user.Organization);
DataContext.Users.InsertOnSubmit(user);
}
else
{
DataContext.Users.Attach(user);
}
DataContext.SubmitChanges();
// Finished here as well.
user.Detach();
}
So, here we are. You'll notice that I comment out the bit where the DataContext attachs to the organization. If I attach to the organization I get the following exception:
NotSupportedException: An attempt has been made to Attach or Add an
entity that is not new, perhaps having
been loaded from another DataContext.
This is not supported.
Hmm, that doesn't work. Let me try it without attaching (i.e. comment out that line about attaching to the organization).
DuplicateKeyException: Cannot add an entity with a key that is already
in use.
WHAAAAT? I can only assume this is trying to insert a new organization which is obviously false.
So, what's the deal guys? What should I do? What is the proper approach? It seems like L2S makes this quite a bit harder than it should be...
Hello Guys,
I'm very new to facebook and wanted to know if this is even possible to do with facebook API.
If a user searches for a name on my website - say "Jamie Smith" - I want to pass this name to facebook and find all users that match that name - so if I can get back their photo and name to display on my site - so users can identify the right person.
I'm using PHP so if there's any example or link that you can provide will be really helpful.
Thanks
Using a SELECT statement in MS SQL 2005 TSQL, and no source table, just variables as listed below...
@FirstName varchar(20)
@LastName varchar(20)
@ZipCode varchar(5)
...what syntax will build XML resembling the following?
<XMLDATA><REC FirstName="JOHN" LastName="SMITH" ZipCode="98052" /></XMLDATA>
Can anyone suggest a good source of names that I can use to help analyze some tables on web pages. The first column of the tables I am scraping have names alone, names and titles or just titles. The names can be as varied as John Smith to Vikram Saksena. I have been poking around for a compiled list of words that can be found in proper names.
Hi :)
I'm looking for a nice newsletter management solution.
I tried CCmail a good script but whaere I can't imort usernames !!!
I would like to find a system that is able to import Opt-in lists in the following format :
John Smith;[email protected];other paramaeters...;[like] ;Male;Age...
I will develop my own module if I could find another emailing manager
Are you already satisfied with a similar application with a trusted (spam-prevention) emailer ?
Thank you :)
Hey all,
Is anyone aware of some code/rules on how to capitalize the names of people correctly?
John Smith
Johan van Rensburg
Derrick von Gogh
Ruby de La Fuente
Peter Maclaurin
Garry McDonald
(these may not be correct, just some sample names and how the capitalization could be/work)
This seems like a losing battle...
If anyone has some code or rules on when and how to capitalize names, let me know :)
Cheers,
Albert
I read different documents how CRF(conditional random field) works but all the papers puts the formula only. Is there any one who can send me a paper that describes about CRF with examples like if we have a sentence
"Mr.Smith was born in New York. He has been working for the last 20 years in Microsoft company."
if the above sentence is given as an input to train, how does the Model works during the training taking in to consideration for the formula for CRF?
Moges.A
i'm joining tables like:
select * from tableA a full join tableB b on a.id = b.id
But the output should be:
row without null fields
row with null fields in tableB
row with null fields in tableA
Like:
a.id a.name b.id b.name
5 Peter 5 Jones
2 Steven 2 Pareker
6 Paul null null
4 Ivan null null
null null 1 Smith
null null 3 Parker
None of the brushes in SystemColors seems to fit the bill, and IIRC, the OS theme beginning with Windows XP uses a gradient. Is there standard OS dialog box background brush or a way to tell WPF that the window is a dialog box and it should paint the background accordingly?
The UISearchDisplayController is very handy and implementing search is pretty straightforward.
However, I bump into problem when, in my app, I want to display search result with empty search string but selected scope button.
It seems like it's a must to enter some search string in order to get the search result table being initialized and displayed.
Is there any ways to display search result immediately after user has picked a scope but not entered search word yet?
Thanks
Bill
I'm retrieving an array of objects from a hidden html input field. The string I'm getting is:
"{"id":"1234","name":"john smith","email":"[email protected]"},{"id":"4431","name":"marry doe","email":"[email protected]"}"
Now I need to pass this as an array of objects again. How do I convert this string into array of objects?
I need to print bill and the size of paper is half of normal 8.5 x 12.
i'm using epson printer..i'm using c#
it doesnt support customizing.please help me...
Imagine if you will a operating system that had the following methods for files
Create File: Creates (writes) a new file to disk. Calling this if a file exists causes a fault.
Update File: Updates an existing file. Call this if a file doesn't exist causes a fault.
Read File: Reads data from a file.
Enumerate files: Gets all files in a folder.
Files themselves in this operating system only have the following meta data:
Created Time: The original date and time the file was created, by the Create File method.
Modified Time: The date and time the file was last modified by the Update File method. If the file has never been modified, this will equal the Create Time.
You have been given the task of writing an application which will sync the files between two directories (lets call them bill and ted) on a machine. However it is not that simple, the client has required that
The application never faults (see methods above).
That while the application is running the users can add and update files and those will be sync'd next time the application runs.
Files can be added to either the ted or bill directories.
File names cannot be altered.
The application will perform one sync per time it is run.
The application must be almost entirely in memory, in other words you cannot create a log of filenames and write that to disk and then check that the next time.
The exception to point 6 is that you can store date and times between runs. Each date/time is associated with a key labeled A through J (so you have 10 to use) so you can compare keys between runs.
There is no way to catch exceptions in the application.
Answer will be accepted based on the following conditions:
First answer to meet all requirements will be accepted.
If there is no way to meet all requirements, the answer which ensures the smallest amount of missed changes per sync will be accepted.
A bounty will be created (100 points) as soon as possible for the prize. The winner will be selected one day before the bounty ends.
Please ask questions in the comments and I will gladly update and refine the question on those.
I was reading a blog entry by Josh Smith where he used a cache mechanism in order to "reduce managed heap fragmentation". His caching reduces the number of short-lived objects being created at the cost of slightly slower execution speed.
How much of a problem is managed heap fragmentation in a managed language like C#? How can you diagnose if it's an issue? In what situations would you typically need to address it?
Please recommend me software engineering/methodology/practices paper. So far I have enjoyed:
1968 Dijkstra : Go To Statement Considered Harmful
Nikalus Wirth : Program Development by Stepwise Refinement
1971 David Parnas : Information Distribution Aspects of Design Methodology
1972 Liskov : Design Methodology for Reliable Software Systems
Extensible Language : Schuman and P Jourrand R. Balzer
Structured Programming :
Dahl - Hierarchical Program StructuresImplementation Patterns
1971 Jim Morris
Protection in Programming Languages
1973 Bill Wulf and Mary Shaw
Global Variable Considered Harmful
1974 : Lisko and Zilles
ADTs
I am looking for a tool which will make able to edit parts of Java code visually using something like inspector and place code back.
For example:
Person p = new Person();
p.setName("Bill Libb");
p.setAge(25);
This code should be generated from visual inspector and copied into Java IDE.
This will help quickly create sample objects for testing.
I'm trying to find an existing Drupal module to fit the bill: basically, when an email fails to send, it should save the email and automatically attempt to resend the email later. I'm using the SMTP module to relay emails through an SMTP gateway (required by the hosting provider), but every once in a while the connection is refused - probably due to the gateway being too busy.
I'm retrieving an array of objects from a hidden html input field. The string I'm getting is:
"{"id":"1234","name":"john smith","email":"[email protected]"},{"id":"4431","name":"marry doe","email":"[email protected]"}"
Now I need to pass this as an array of objects again. How do I convert this string into array of objects?
With an XML configured Spring bean factory, I can easily instantiate multiple instances of the same class with different parameters. How can I do the same with annotations? I would like something like this:
@Component(firstName=”joe”, lastName=”smith)
@Component(firstName=”mary”, lastName=”Williams”)
public class Person { /* blah blah */ }
I'm looking for a thin, generic layer (probably written in PHP) that sits between a database (probably MySQL) and web service clients (which could be anything). I imagine there would be config files of some sort that tell it how to map web service requests to database queries (or other DB commands). It would also need to handle authentication and authorization, of course.
I've done some googling but failed to find anything that fits the bill. Can anyone suggest something like this?
What is the standard way to throw and catch exceptions in R6RS Scheme? I'm looking for syntax that works in any version of Scheme (not just PLT) that implements R6RS.
R6RS guard syntax looks like it might fit the bill, but can somebody show me an example of how to actually use it?
Given a DBIx::Class resultset, for example:
my $rs = $c->model("DB::Card")->search({family_name => "Smith"});
the tutorials I've read use the stash to pass an arrayref of rows:
$c->stash->{cards} = [$rs->all];
This results in the query getting executed at this point, and the resulting objects stuffed into the stash, so they can be used in TemplateToolkit as:
[% FOREACH card IN cards %]
[% card.given_name %] [% card.family_name %]
[%END%]
Is there a proper way to have TT iterate over the rows as they get fetched from the DB?
Most MVVM examples I have worked through have had the Model implement INotifyPropertyChanged, but in Josh Smith's CommandSink example the ViewModel implements INotifyPropertyChanged.
I'm still cognitively putting together the MVVM concepts, so I don't know if:
you have to put the INotifyPropertyChanged in the ViewModel to get CommandSink to work
this is just an aberration of the norm and it doesn't really matter
you should always have the Model implement INotifyPropertyChanged and this is just a mistake which would be corrected if this were developed from a code example to an application
What have been others' experiences on MVVM projects you have worked on?
Hi I have a JSON string that looks like this (Usingt Rails and a REST service)
{
person:
{
name:"Pepe",
last:"Smith"
hats:[ { team:"lakers", color:"purple"}, { team:"heats", color:"red" }] } }
I want to be able to able to get that JSON, and save the Person to the database, but I want to save the "hats".. as a string to the database; without parsing it or anything like that
i.e. I want to save this to SQL:
hats = "[ { team:"lakers", color:"purple"}, { team:"heats", color:"red" }] }"
Is there a way to do this in rails?