Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6551461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:20:29+00:00 2026-05-25T12:20:29+00:00

I have some problems with LINQ-to-SQL and anonymous types. I have gridview (it’s not

  • 0

I have some problems with LINQ-to-SQL and anonymous types.

I have gridview (it’s not that important, but it is Telerik’s RadGrid) which has the following datasource:

TSEntities db = new TSEntities();

        int idFirma = Convert.ToInt16(Request.QueryString["idt"]);

        var ticketList = (from t in db.Ticket 
                          where t.idFirma == idFirma
                          select t).ToList();


        gvTicketi.DataSource = from t in ticketList
                               where t.idFirma == idFirma
                               orderby t.idTicket, t.RedniBroj, t.DatumPrijave
                               select new { t.idTicket, t.idFirma, t.idKontakt, t.idManager, t.idNadredeniTicket, TicketNumber = t.idNadredeniTicket + "-" + t.RedniBroj, t.Biljeske, t.DatumDo, t.DatumPrijave, t.OpciPrioritet, t.Opis, t.OpisZatvoren, t.Prioritet, t.Status, t.Tip, t.VrstaPrijave, t.Zatvoren, NazivKontakta = t.Kontakt.Ime + " " + t.Kontakt.Prezime };

Everything works fine when NazivKontakta isn’t null, but when is null everything crashes with the following error: “Object reference not set to an instance of an object” which explains everything, but doesn’t help me to work it out.

What I’d like to do (if possible) is to somehow check for the null value and if it is null I’d like to set “NazivKontakta” to string value “Empty” and if it’s not null value to set it to the values from the database.

Is there a a solution for this? Any help would be appreciated!

Thank you in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:20:30+00:00Added an answer on May 25, 2026 at 12:20 pm

    I suspect it’s actually this which is causing the problem:

     t.Kontakt.Ime + " " + t.Kontakt.Prezime
    

    i.e. not NazivKontakta being null, but t.Kontakt being null. After all, if nothing’s dereferencing NazivKontaka, there shouldn’t be a problem.

    Try this in your query:

    NazivKontakta = t.Kontakt == null ? "" : t.Kontakt.Ime + " " + t.Kontakt.Prezime
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some problems with linq-to-sql lately. The problem is that it thinks
Some background: I have an database that I want to use linq-to-sql to update
I have some problems with OpenCV s cvCanny(...) and the Image data types it
i want to use .animate function but i have some problems i want to
I have some linq to sql method and when it does the query it
I'm playing with LINQ-To-SQL in .NET 3.5 and have built some classes based on
What are some clever uses for LINQ outside of LINQ to SQL? Have you
I'm having some problems with the Sql query generated by LINQ, Since my environment
I am still facing some problems when using LINQ-to-SQL. I am also looking for
I know that Entity Framework has some LINQ support problems (at least in comparison

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.