0

I have trouble to getting my linq line to work.

var result = databaseObjects.Where(dbo => dbo.GetType() == typeof(Model.DatabaseTable) ? (dbo as Model.DatabaseTable).FullName.Equals(name) : dbo.Name.Equals(name));

I tried to use the method from an answer to this question to make it work. I think i know what is wrong, DatabaseObject is a abstract class, and i want to to avoid to use FullName property on everything else than DatabaseTable, but from what i can see it does check on it.

EDIT: The Error was:

System.NullReferenceException was unhandled
{"Object reference not set to an instance of an object."}

Problem was i forgot to assign DatabaseObject.Name, DatabaseTableObject.FullName was assigned.

1
  • i forgot to assign Name, on the objects other than DatabaseTable, a stupid mistake, and i kept looking into the linq expression, which was not wrong :) Commented Dec 11, 2012 at 14:47

1 Answer 1

3

Looks as though either FullName or Name is null on one of your dbo objects. To verify change your code to:

var result = databaseObjects.Where(dbo => dbo.GetType() == typeof(Model.DatabaseTable) ? (dbo as Model.DatabaseTable).FullName == name : dbo.Name == name); 

It's shouldn't throw an exception.

Sign up to request clarification or add additional context in comments.

2 Comments

I know found out during maintenence here on stack overflow :) wanted to pull question down before that, but was too slow. Thank you anyway
Leave the question it may help others. I would even sugest updating the question to show what error message you were getting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.