Dell Released

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Thursday, August 29, 2013

Updating foreign key references on the DbContext ChangeTracker

Posted on 7:07 AM by Unknown
Updating foreign key references on the DbContext ChangeTracker



I work with EF 5.0, DB first in a web project.

For our service layer, we use Agatha with AutoMapper, so all data arrives

in the service layer as POCO objects.

I have a data structure that look like this:

public class FirstClass

{

public int Id { get; set; }

public int? SelectedSecondClassId { get; set; }

public SecondClass SelectedSecondClass { get; set; }

public ICollection<SecondClass> MySecondClasses { get; set; }

//other properties go here

}

public class SecondClass

{

public int Id { get; set; }

public int ParentSecondClassId { get; set }

public SecondClass ParentSecondClass { get; set; }

//other properties go here

}

Now imagine I try to update a FirstClass object and do the following in 1 go:

Create 2 new Secondclass objects in the MySecondClasses collection (both

with id 0)

Set one of these newly created objects as the SelectedSecondClass

Then EF refuses to play ball. I can't get it to work. If I look in the

changetracker, I see that the SelectedSecondClass on the entity is empty

again, but the SelectedSecondClassId is set to 0. And that's something he

can't resolve, because there are 2 objects with Id 0, before they are

properly created.

If I do this, I can get stuff fixed:

var newId = -1;

foreach (var newSecondClass in firstClass.MySecondClasses.Where(x => x.Id

<= 0))

{

newSecondClass.Id = newId;

newId --;

}

if (firstClass.SelectedSecondClass != null)

{

firstClass.SelectedSecondClassId = firstClass.SelectedSecondClass.Id;

}

// Send the updates to EF

As you understand, I feel like this is a bit hacked together and it would

be easy for another developer to forget something like this. I would like

to have a better way of doing this. Preferably in a way that I can 'fix'

situations like this just before a SaveChanges() in my DbContext wrapper.

Can anybody point me in the right direction?
Read More
Posted in | No comments

Convert string to DateTime and format

Posted on 4:51 AM by Unknown
Convert string to DateTime and format



Can i convert the string below to DateTime

Friday, 27th September 2013

This is what i want to achieve:

String tmpDate="Friday, 27th September 2013";

closingDate = Convert.ToDateTime(tmpDate).ToString("yyyy-MM-dd");

Doing above i get error:

The string was not recognized as a valid DateTime. There is an unknown

word starting at index 10.
Read More
Posted in | No comments

Wednesday, August 28, 2013

call function on click outside of a particular div

Posted on 10:54 PM by Unknown
call function on click outside of a particular div



I am having a html structure as

<div class="abc">

<div id="test">

<label>Name</label>

<input type="checkbox">

<label>Name</label>

<input type="checkbox">

<label>Name</label>

<input type="checkbox">

</div>

</div>

I want that when i click outside of div id test, a particular function can

be called. and also no event shall be triggered when inside the div id

test i.e when I click the checkboxes, no event shall be triggered.

Any help will be really appreciated.
Read More
Posted in | No comments

OperationalError when inserting into sqlite 3 in Python

Posted on 2:10 PM by Unknown
OperationalError when inserting into sqlite 3 in Python



I'm populating a database with data that I parse from JSON. When I execute

my INSERT statement, I get an error: sqlite3.OperationalError: no such

column: None. Some of the JSON data returns null, which would cause Python

to insert None into the table, but I believe this should be fine? Does

anyone know what the problem is?

Traceback: Traceback (most recent call last): File

"productInfoScraper.py", line 71, in <module> ")")

My INSERT statement in Python:

cursor.execute("INSERT INTO ProductInfo VALUES(" +

str(data["data"]["product_id"]) + ", " +

"'" + str(data["data"]["product_name"]) + "'" + ", " +

"'" + str(data["data"]["ingredients"]) + "'" + ", " +

"'" + str(data["data"]["serving_size"]) + "'" + ", " +

str(data["data"]["calories"]) + ", " +

str(data["data"]["total_fat_g"]) + ", " +

str(data["data"]["total_fat_percent"]) + ", " +

str(data["data"]["fat_saturated_g"]) + ", " +

str(data["data"]["fat_saturated_percent"]) + ", " +

str(data["data"]["fat_trans_g"]) + ", " +

str(data["data"]["fat_trans_percent"]) + ", " +

str(data["data"]["cholesterol_mg"]) + ", " +

str(data["data"]["sodium_mg"]) + ", " +

str(data["data"]["sodium_percent"]) + ", " +

str(data["data"]["carbo_g"]) + ", " +

str(data["data"]["carbo_percent"]) + ", " +

str(data["data"]["carbo_fibre_g"]) + ", " +

str(data["data"]["carbo_fibre_percent"]) + ", " +

str(data["data"]["carbo_sugars_g"]) + ", " +

str(data["data"]["protein_g"]) + ", " +

str(data["data"]["vitamin_a_percent"]) + ", " +

str(data["data"]["vitamin_c_percent"]) + ", " +

str(data["data"]["calcium_percent"]) + ", " +

str(data["data"]["iron_percent"]) + ", " +

"'" + str(data["data"]["micro_nutrients"]) + "'" + ", " +

"'" + str(data["data"]["tips"]) + "'" + ", " +

str(data["data"]["diet_id"]) + ", " +

"'" + str(data["data"]["diet_type"]) + "'" +

")")

My CREATE TABLE statement:

cursor.execute("CREATE TABLE ProductInfo(product_id INT, product_name TEXT,\

ingredients TEXT, serving_size TEXT, calories INT, total_fat_g INT,\

total_fat_percent INT, fat_saturated_g INT, fat_saturated_percent INT,\

fat_trans_g INT, fat_trans_percent INT, cholesterol_mg INT, sodium_mg\

INT, sodium_percent INT, carbo_g INT, carbo_percent INT, carbo_fibre_g\

INT, carbo_fibre_percent INT, carbo_sugars_g INT, protein_g INT,\

vitamin_a_percent INT, vitamin_c_percent INT, calcium_percent INT,\

iron_percent INT, micro_nutrients TEXT, tips TEXT, diet_id INT, diet_type\

TEXT)")
Read More
Posted in | No comments

Trying to print a string character by character with delay between two character print

Posted on 12:20 PM by Unknown
Trying to print a string character by character with delay between two

character print



I've tried with code below. please guide me where i am wrong??? The

desired output is like..

m(delay)e(delay)s(delay)s(delay)a(delay)g(delay)e.

import java.util.*;

import java.applet.*;

import java.awt.*;

/*<applet code="MessageWithDelay" width=400 height=200>

</applet>*/

public class MessageWithDelay extends Applet implements Runnable {

Thread t;

//char msg[] ={"m","e","s","s","a","g","e"};

String str = "message";

Graphics bufferg;

Image buffer;

int counter=0,x=str.length(),i=0;;

public void init() {

//initializa the thread

t = new Thread(this);

t.start();

Dimension d = getSize();

buffer = createImage(d.width,d.height);

}

public void run() {

try {

while(true)

{

//requesting repaint

repaint();

if(counter==x)

{

Thread.sleep(200);

counter=0;

i=0;

}

else

{

Thread.sleep(400);

}

}

}

catch(Exception e) {

}

}

public void update(Graphics g) {

paint(g);

}

public void paint(Graphics g) {

if(bufferg == null) {

Dimension d = getSize();

bufferg.setColor(Color.green);

g.setFont(new Font("Comic Sans MS",Font.BOLD,36));

bufferg.drawString(str.charAt(i)+"",20,20);

counter++;

i+=1;

//update screen

g.drawImage(buffer,0,0,this);

}

}

}

I am working on command prompt and its giving me bunch of different

errors. I want to know why the errors occurring if anyone could explain me

by trying it. Thanx in advance.
Read More
Posted in | No comments

I need to make my JPanel resize dynamically as new components are being added to it

Posted on 9:38 AM by Unknown
I need to make my JPanel resize dynamically as new components are being

added to it



I need to let users add more text fields to my JFrame so once the size of

the frame has exceeded its original value a scroll pane would step in.

Since I cannot add JScrollPane to JFrame in order to enable scrolling I

decided to put the JPanel on the JFrame and pass the JPanel object into

the JScrollPane constructor. Scrolling now works fine but only until it

has reached the borders of the JPanel. The thing is the size of JPanel

stays as is and is not stretching dynamically. What happens is the buttons

in my code are using up all the space of the JPanel being the size of

300x300 but what I want to do is have JPanel stretch once these controls

have used up its original space. Please advise.

import java.awt.Dimension;

import java.awt.FlowLayout;

import java.awt.GridLayout;

import java.awt.Rectangle;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.ScrollPaneConstants;

public class Skrol {

public static void main(String[] args) {

JFrame f = new JFrame();

f.setLayout(new FlowLayout());

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel p = new JPanel();

p.setPreferredSize(new Dimension(400,400));

JScrollPane jsp = new JScrollPane(p);

jsp.setPreferredSize(new Dimension(300,300));

jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);

for(int i=0;i<100;i++)

{

JButton b = new JButton("Button "+i);

p.add(b);

}

f.add(jsp);

f.setSize(new Dimension(600,600));

f.setLocation(300, 300);

f.setVisible(true);

}

}
Read More
Posted in | No comments

How to retrieve images from cache memory?

Posted on 6:40 AM by Unknown
How to retrieve images from cache memory?



I am using picasso library for loading images .In default picasso, It uses

internal cache memory for loading images.But as per my app configuration

,i have to use external cache memory(Cache on Disk). so i used this code

for Cache on Disk

File httpCacheDir = new

File(getApplicationContext().getExternalCacheDir(),"http");

long httpCacheSize = 10 * 1024 * 1024; // 10 MiB

HttpResponseCache.install(httpCacheDir, httpCacheSize);}

Picasso is flexible. So now it caches images in external Sd card..

The caches is stored in sdcard/android/data/packagename/cache/http The

caches are stored in ".1" ,".0". formats so i just opened them and changes

into ".1" to ".jpg".it gives exact images what i need. But how to do in

programatically? but picasso itself caches my memory in to my app for

loading image into imageview.but i have to download images from cache

memory..any help?
Read More
Posted in | No comments
Newer Posts Older Posts Home
Subscribe to: Posts (Atom)

Popular Posts

  • Cannot connect to SQL Server 2012
    Cannot connect to SQL Server 2012 I'm trying to connect to a SQL Server 2012 database using C#, both the server and program are on the s...
  • Mirrors Edge video settings are locked
    Mirrors Edge video settings are locked How do you change the video settings in Mirror's Edge? For me they are all grayed out and locked ...
  • A div that adapts to its background
    A div that adapts to its background Is it possible to make a div adapt to the img that its in the background? Clarification: I do not mean t...
  • candied mints storage and transporting long distance
    candied mints storage and transporting long distance I'm making mints for my nephew's wedding (containing powdered sugar, butter, wh...
  • Fix column width with tabularx
    Fix column width with tabularx I want to create a table with 100% width? The first two columns should have a minimum width and the last colu...
  • URL constantly results in a badbox
    URL constantly results in a badbox I am trying to insert a long url into a latex document. I'm using hyperref package to make them click...
  • filtration on the cohomology of a complex
    filtration on the cohomology of a complex Let $K^\bullet$ be a complex and let $F_I$ and $F_{II}$ be two filtrations on it. suppose $F_I^i K...
  • Application or Object defined error - VBA Excel 2013
    Application or Object defined error - VBA Excel 2013 I want code to check one column of data for a condition ie: Range Qualification. If the...
  • Trying to print a string character by character with delay between two character print
    Trying to print a string character by character with delay between two character print I've tried with code below. please guide me where...
  • for loop with two integers
    for loop with two integers i'm new here. I would like to know, how to use for loop with 2 integers. Let's say: for (int x = 1, int ...

Categories

  • Games
  • News
  • Streak 5
  • Streak 7
  • Tips

Blog Archive

  • ▼  2013 (124)
    • ▼  August (124)
      • Should I make multiple SQLite databases for better...
      • Difference between Nil and nil and Null in Objecti...
      • Cannot connect to SQL Server 2012
      • Android - error opening file just created
      • PHP SimpleXML doesn't output anything
      • Memory leak (igraph, watts.strogatz.game, get.all....
      • How do I position a div on top of another div
      • Updating foreign key references on the DbContext C...
      • Convert string to DateTime and format
      • call function on click outside of a particular div
      • OperationalError when inserting into sqlite 3 in P...
      • Trying to print a string character by character wi...
      • I need to make my JPanel resize dynamically as new...
      • How to retrieve images from cache memory?
      • how to add jscrollpane to jframe?
      • Query on how to Select Date before the latest Date...
      • Does archive size of tar, zip and rar effect the t...
      • How do I make a DOM object follow a circular path ...
      • how to use for loop for my issue
      • AngularJS - Pass variable from a controller & upda...
      • Windows 2012: how to make power button work in eve...
      • IN OBOUT grid, how to move from first grid to anot...
      • Am I using the form action correctly?
      • Increasing the font size of a webview conflict wit...
      • quicktags "link" button doesn't work, but all othe...
      • Cannot access local variables using systemtap
      • Remove/avoid adding target link to URL
      • Left-justified equations with left tags (so it loo...
      • [ Marriage & Divorce ] Open Question : My boyfrien...
      • livetv2pc)))WaTch (Rugby) Australia vs New Zealand...
      • The Google Visualization API Query Language: Query...
      • iOS 7 phone-number link doesn't work when webpage ...
      • Cross-browser textarea maxlength
      • candied mints storage and transporting long distance
      • how to convert objectHTML into html
      • Mellin transform definition
      • Multiple Google Calendars with one Google Cal ID
      • Dell PowerEdge 2950 PCIe Training Error -- No PCIe...
      • Reset Disk - Windows Storage Server 2012
      • Windows Phone 8 - Keeping background location trac...
      • Django forms design suggestiom
      • Magento Upgrade, getting error with tier prices fr...
      • Bouncing between "Adapter is detached" and "No wra...
      • How to create overlapping - not stacking - shapes ...
      • Enclosing capsules around list based arrays [on hold]
      • Identifying Switch case argument (Perl)
      • asp.net ModalPopupExtender not behaving properly
      • fanotify unable monitor entire system for FAN_OPEN...
      • Jquery UI datepicker inline "onclick" handler caus...
      • URL constantly results in a badbox
      • Split values over multiple rows with different del...
      • How to aggregate data without group by
      • Angular $scope.$watch on (for in... ) don't work
      • Using Modernizr to test browser support for css ca...
      • Content overlapping in navigation menu?
      • cls file - multiple files
      • Differences between "fortification nouns"
      • filtration on the cohomology of a complex
      • Problems with every aspect of facebook that involv...
      • Extract data from last line in a text file using PHP
      • How to properly provide data for ?
      • ConditionalPanel doesn't support variables with do...
      • Frequent out of memory issues
      • Undefine reference for libraries, so How could I f...
      • radio buttons checked with jquery not holding prop...
      • How to modify bash command to change permissions
      • header(Content-type: image/jpeg) not working
      • Removing smart quotes from an SQL server text column
      • Getting out of sync server response
      • thesis work" vs "thesis
      • php radio post wrong same value after submit
      • Several questions about trigonometry and functions
      • A div that adapts to its background
      • Why are there two different versions of the mean a...
      • Restore only some volumes from a multiOS system image
      • system of pde (solid mechanics)
      • Application or Object defined error - VBA Excel 2013
      • Deleting the last few revisions: SVN best practice
      • Choose blackberry 10 platform to use call logs, me...
      • Procedure or function usp_logout has too many argu...
      • how can i use combination of unix signals (like SI...
      • Basic Javascript Countdown Timer Taking Longer Tha...
      • WordPress Guest Author - How can I use custom fiel...
      • button to generate html delete method?
      • socket.io redis ECONNREFUSED
      • Can one http request call multiple css files?
      • .htaccess related codeigniter. why error 404 page ...
      • Undefined symbols error from static framework
      • XML Sitemap Generator for URL with 1.5 million pages?
      • How do I prevent Microsoft DNS from reporting vers...
      • Solve the equation for x, y and z: $\sqrt{x-y+z}=\...
      • A basic doubt on linear dependence of vectors
      • mysql charsets, can I perform the conversion in py...
      • Mirrors Edge video settings are locked
      • Receiving null messages on android, how to fix it?
      • changing an onEdit function to run onOpen
      • Handle Multiple Form tag in asp.net page?
      • Getting click event on parent page of button in frame
      • Fix column width with tabularx
      • best software to use to make a website
      • NSLog returns (null) when logging string from anot...
      • Add express middleware for param validations
      • R "object x not found error" in calling self-defin...
      • Android Application for Registration to a website
      • How to insert multiple Facebook comment boxes on o...
      • How can I group by the difference of a column betw...
      • for loop with two integers
      • Why is unsigned integer overflow defined behavior ...
      • Using multiple SELECT statements to narrow results
      • Android: Logout system and the android lifecycle
      • how to use font awesome in own css?
      • Nested Lists in Spring Expression Language
      • Live USB quit working...HELP :-)
      • Need help in drawGradientArea
      • django-ckeditor Image Browsing
      • C3P0 connection Pooling issues
      • Code keeps entering values into array backwards
      • Number of permutations with repeated objects.
      • How do I suspend a certain process when display is...
      • How to free Watch Houston Texans vs Minnesota Viki...
      • UPS Shipping required I get a new account ID and n...
      • Java concurrency - Is this efficient?
      • Are floated element really removed from normal htm...
      • How to implement Jquery Text Editor with Hindi Lan...
  • ►  2012 (6)
    • ►  February (2)
    • ►  January (4)
  • ►  2011 (10)
    • ►  December (1)
    • ►  November (2)
    • ►  October (7)
Powered by Blogger.

About Me

Unknown
View my complete profile