Architecture :: Check For Nulls In An Object Aggregation?

Dec 30, 2010

I am working on a legacy application. It uses custom MVC framework and Windows Communication Framework service to bridge the Presentation layer with the rest of the application (i'll call this AppServer).

Every Entity in the AppServer inherits from BaseEntity which contains the method:

[Code]....

As you can see:

if the personObject was not null, but the ContactAddress was, [which is exactly what happens in the construction of a PersonObject in the event that no contact details are provided (hence they are not present in the HashTable and dont get created)] then the code will fail with a null reference exception.

SO:

Is there a fundamental flaw in the way that objects are getting created? It would be easy to point the finger in this direction, however, im sure there must have been some reason for the original architect to choose not to instantiate an empty ContactAddress object every time a Person object is referenced - EG if in a particular Presention->AppServer Request/Response cycle we only want a person's login details - we wouldn't care about the ContactDetails.

FINALLY MY QUESTION:

Is there a clean way to check for null objects within an aggregation, without doing something like:

if(Parent!=null)
if(Parent.child!= null)
if(Parent.child.child != null)

It just looks messy and it seems such a common problem, im sure there would be a better way of doing things.

View 5 Replies


Similar Messages:

DataSource Controls :: Check For Columns With All Nulls?

Jan 5, 2010

I have a situation where a query returns ~20 columns, but at any given execution only 5 of the 20 will have non-NULL values. The remaining 15 will contain null for every row in those columns.

I need to figure out which of the 5 columns have values. I am using a SqlCommand. How would I best approach figuring out these 5 columns?

View 5 Replies

Architecture :: Looking For Better Way To Design, To Use Object's Properties With The Object Data Source?

May 10, 2010

I've posted the same question in the Object Data Source forum. This is a link to it http://forums.asp.net/t/1554083.aspx. Maybe I should've posted here to begin with. There seemed to be some overlap so I wasn't sure which was the best on to post the question in.

I'm trying to get a better understanding of how I could've designed my app so that the Object Data Source could work with the properties of my business objects. Please read the other post to see how it's currently being done. Sorry for the link to the other page. I didn't want to post a bunch of duplicate information. I would love to get some suggestions for alternative ways of doing this.

View 1 Replies

Forms Data Controls :: Aggregation And Sum In Gridview From Textboxs Required Examples?

Aug 27, 2010

how to do aggregation and sums in gridview from textboxs required examples

ex: while trading in stock market it was chnaging dynamically how it was working explain with examples

View 1 Replies

Architecture :: Store ID Or Object In DTO Object?

Jun 15, 2010

I'm currently creating a Class Library for DTOs and was wondering if I should store an ID or an Object

For example:

ProductDTO (class)
ID (Int32)
Code (String)
Description (String)

[Code]....

View 1 Replies

Web Forms :: Check Processor Architecture 64 Or 32 Bit?

Feb 26, 2010

I need to direct people to a different download version depending on whether they are running 64 or 32 bit processors. Can anyone tell me how to determine the processor type when someone hits your web page?

View 1 Replies

Architecture :: Want To Make Public Object On ,net Page

Aug 27, 2010

in asp.net can i make public objects on my page, for example

public Customer cust1 = new customer();

and use this object on my entire code?

what are the drawbacks of creating public objects??

a single object will be created for all users??? or each user will have a different object?

View 2 Replies

Architecture :: Code In Object Oriented Pattern?

Oct 4, 2010

I am creating an authentication service. This service has one of the methods to validate username and password and return a status based on it.

The validation method has bunch of things to check before it can say user is valid. This method has a pseudo code similar to this:

If UserName and Password is correct

If User Account is Locked (due to invalid attempts)

{[code]....

As you can see there are lots of if else statements that I am writing. It looks more like a procedural programming rather than object oriented.How can I fit such kind of code in object oriented pattern?

View 2 Replies

Architecture :: Insert Data With Business Object?

May 29, 2010

I do not know how to create a business object for inserting data into the database.

View 2 Replies

Architecture :: Object Instances In High Performance Web Applications

Sep 21, 2010

Imagine I have a class MyTestClass. And I need an instance of this Type throughout my whole web application.Now there are several possibilities to accomplish this.1. Make MyTestClass static, make it contain static methods only
Probably the most performant solution. I'm not feeling lucky about using static fields though. Thread safety? What if my static class contained a static System.Collections.Queue?

View 8 Replies

Architecture :: Design System With Pure Object Oriented?

Aug 4, 2010

Analysis and design C# application with pure object orineted feature .

for example

I get all the requirement for the user, How to analysis the system , keeping future changes in mind , design and system with pure object oriented feature .

in Short : design system with pure object oriented feature so that it flexible so that in future new version can be launch easily

View 1 Replies

Architecture :: Handling Collections Related To An Object Not Yet Persisted

Nov 15, 2010

how do you treat situations where there is the need of storing collections of object belonging to an object not persisted on db (not yet). For example , suppose we have a web application for submitting orders. The user click on 'Create new order" , then insert order's data , choose items from a catalog and add them to the order. Finally he "submit" the order. I can see two different way to persiste data :

a) create on db an empty order instance when user click on "create new order" , so that the orderitems collection could be directly associated (saved) with that instance in the db.

b) keep all data in memory and finally save order and orderitem.

The b option imply storing (in session?) the orderitems collection till submit. Are there, probably, other solutions. Which are best practices in these situation?

View 4 Replies

Architecture :: Business Object Design In Master Details?

Aug 19, 2010

I have the following scenario,There is a master business object containing 40 fields2 separate child business objectsIf I update a child record, I have to update master's 'Last modify by' status along with 3 or more fields in masterFor this purpose, I don't want to initialize a separate Master class object (as most of the fields are unused/wasted)The 'last modify by' also gets updated if the records in master get updated themselvesCurrently I have separate business objects for master table, Child 1, Child 2 etc.

How do I control this in my business object design ? Do I break up my master object ? Say I extract last 'modify by ' into a new class, through inheritance or some other way ?Is there a way that whenever child gets updated I use a 'small' class to update Master status only and whenever the master itself gets updated I do the same.Problem is that I am having redundancy in my small class (Master class also contains 'Last Modify By ',

View 5 Replies

Architecture :: Object Life Cycle - What Is The Order Of Events?

Jan 13, 2010

I'm trying to better understand the life cycle of an object in the .Net framework. My companies Intranet has some custom classes that were written by a vendor that I'm trying to make some modifications to. Specifically I want to set some variables & hashtables to null when use of the object is done. For now I have this in the dispose event.

Is there any info you can point to that would be good reading on the life cycle of an object in the .Net framework? I.e. what order do the events fire in? OnInit, Initialize, finalize Dispose, etc. I have the ASP.net page lifecycle but I'm not looking for that.

View 3 Replies

Check For Byte() In An Object?

Mar 15, 2010

I have a datatype defined as 'Object', using this variable I am passing

View 2 Replies

Architecture :: What Is Role Of Object Properties When Using Client Side Validations

Aug 24, 2010

I have been using properties and have idea that using properties with private fields we can implement validations and buisness rules in them.

But I am just thinking asp.net client side validation controls provide good strength and they provide good user experience as well. They can be used for any type of validation (using regular expression) on client side and their re-use is possible on server side. When validation controls are a must and they are powerful; is making properties not just wastage of time ?

Is there still some use of properties ?

View 6 Replies

Architecture :: Method Return Types Object Vs String/bool

May 27, 2010

If I'm returning an object, then it's pretty straight-forward. However, if I'm just trying to return whether or not the method was successful or not, what's the best option? Sure ... bool seems obvious - but what if you need to debug or get some additional details out of the method than just "yes/no"? Well that's where a string becomes more obvious, right? You can leave it empty to say that the method was successful or chock it full of details in the case of an error. But this can make it less intuitive to others who may have to run your functions and it also jumbles up everything you wanted to pass back into one large string.

View 3 Replies

Check If An Object (DropDown) Exists?

Dec 18, 2010

How do, to see if an object exists? For example, I want to see if there is a DropDown on the page. I tried this:

if (object != null) {}

But it does not work.

View 2 Replies

C# - Column Does Not Allow Nulls

Mar 14, 2011

have a look at my code below and tell me where i am going wrong.

case "particulars.aspx":
dt = JobCardManager.GetParticularsByJobId(id);
hidJobId.Value = id.ToString();
if (dt != null && dt.Rows.Count > 0)
{
gvParticulars.DataSource = dt;
gvParticulars.DataBind();
else
[code]...

View 2 Replies

MVC :: Handle Nulls In Views?

May 21, 2010

I have an Edit View with a bunch of fields, some non-required. If the user decides not to fill them in, thats fine and it gets saved to the database as nulls (nullable fields).

The problem is when the controller redirects to the Details page and tries to render these null objects in labels using LabelFor(Model.SomeNonRequiredField)

Where/How should i be handling "acceptable" nulls?

Right now in my service layer im manually setting these nulls to String.empty before committing to the db, but now its saving it as an empty character instead of null - something like "SetDefaultValuesForNonRequiredFields(myObject)"

View 1 Replies

Check For A Null Object Reference When Validating Forms In MVC?

May 28, 2010

I'm experimenting with validating forms in the asp.net MVC framework. I'm focusing on server side validation for the time being. I've come across an error that I'm not sure how to rectify. System.NullReferenceException: Object reference not set to an instance of an object. The code that throws the error is:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Exclude="ID")] MembersCreate mc )
{
mc.Modules = ModuleListDataContext.GetModuleList();
ViewData.Model = mc;
//Validation using ModelState
//
//
//line below errors when form field is empty
//
if ((string)mc.Member.Username.Trim() == "")
ModelState.AddModelError("Member.Username", "Username is required.");
if (!ModelState.IsValid)
return View();
try
{
// TODO: Add insert logic here
return RedirectToAction("Index","Home");
}
catch
{
return View();
}
}

When I put spaces in the field it performs exactly as i want, but if I leave the field blank and press submit I get the error. What's the best way to avoid this error and still validate blank form fields?

View 1 Replies

WebMatrix :: PageData Passes Nulls?

Oct 26, 2010

Caller to Draw.cshtml

if (errors == false)
{
PageData["Range"] = zoom;
PageData["StartReal"] = startRe;
PageData["StartImaginary"] = startIm;
PageData["StartColor"] = startColor;
PageData["N"] = N;
PageData["SizePic"] = sizePic;
@:<img src="@Href("Draw.cshtml")" />;
}

Here all variables have a value, however when arriving in Draw.cshtml the PageData all pass as null.

Draw.cshtml
@{
var zoom = PageData["Range"];
var startRe = PageData["StartReal"];
var startIm = PageData["StartImaginary"];
var startColor = PageData["StartColor"];
var N = PageData["N"];
var sizePic = PageData["SizePic"];
Bitmap bitmap = new Bitmap(sizePic, sizePic);
Graphics g = Graphics.FromImage(bitmap);
Pen myPen = new Pen(Color.Red);
juliaset(zoom, startRe, startIm, startColor, N, sizePic, g, myPen);
Response.ContentType = "image/jpeg";
Response.AddHeader("content-disposition", "inline; filename=test.jpg");
bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
bitmap.Dispose();
myPen.Dispose();
}

View 2 Replies

Databases :: Sql Cursor Pulls In All Nulls For Every Field In Every Row?

Mar 19, 2010

I am using a cursor to iterate through a small set of record (28), perform some maths on each record and then update the record / row.

The problem is the cursor pulls in all nulls for every field in every row

It also gives me 28 rows, 28 times (see below)

[code]......

View 1 Replies

Databases :: NoNullAllowedException: Column 'idNames' Does Not Allow Nulls

Apr 12, 2010

environment: VS2008, MySQL 5.1.45, .net Connector 6.2.2

Error msg:

NoNullAllowedException: Column 'idNames' does not allow nulls.

The MySQL DB has on "idNames" (Primary Key) a tick-mark for: primary Key, Not Null, Auto-Increment Also: I can add/retrieve records via the 'MySQL Query Browser'; I see the data via VS2008 'Preview Data'!

As said in the comment below; when the 'idNames' is explicitely given the rows.add works fine. So it seems that I miss something around the 'auto-increment' business!

[code].....

View 2 Replies

Databases :: Detecting Nulls In Output Parameter Using ODP?

May 17, 2010

I'm converting my application from using System.Data.OracleClient to Oracle.DataAccess.Client and I've noticed some weird behavior.

I am calling a stored procedure that sets an output parameter value. Under some circumstances, a null value gets assigned to this value and I need to detect it.

Here's how I'm declaring it using ODP.net:

cmd.Parameters.Add("p_status", OracleDbType.VarChar2, 200, DBNull.Value, ParameterDirection.Output)

The old Microsoft driver for Oracle would read the value as an empty string. However, ODP is returning a value {null} (per Visual Studio's debugger), which is not equivalent to null, DBNull.Value, nor an empty string. As a result, the code doesn't branch correctly now.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved