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

  • Home
  • SEARCH
  • 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 876611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:27:42+00:00 2026-05-15T11:27:42+00:00

var ID, x,y switch(ItemTypeNo) { case ItemType.A : ID = from s in cntx.Tablo1

  • 0

var ID, x,y

switch(ItemTypeNo)
{

   case ItemType.A : 

    ID = from s in cntx.Tablo1
break;


   case ItemType.B : 

    ID = from s in cntx.Tablo2
break;


   case ItemType.C : 

    ID = from s in cntx.Tablo3
break;

}

  • 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-15T11:27:42+00:00Added an answer on May 15, 2026 at 11:27 am

    You can only use var for inline initialization, which that isn’t. You would need to type ID appropriately, and since var has a single type that would only work if Tablo1, Tablo2 and Tablo3 are the same type (which seems unlikely).

    What is it you need to do here?

    There is a scenario that works here; when selecting a common type from each; let’s assume thay all have an int primary key:

    IQueryable<int> ids;    
    switch(ItemTypeNo)
    {    
       case ItemType.A : ids= from s in cntx.Tablo1 select s.Id; break;
       case ItemType.B : ids= from s in cntx.Tablo2 select s.Id; break;
       case ItemType.C : ids= from s in cntx.Tablo3 select s.Id; break;
       default: throw new InvalidOperationException();
    }
    

    However, in the general case… not so much. You could type ID as the non-generic IQueryable, but to be honest that doesn’t let you do very many interesting things. And dynamic doesn’t play nicely with LINQ (and even if it did, it would be a hack here).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: _trackit: function(){ for(var key in this.items.sublinks){ switch(key){ case 'shoes': for(var
var foo1,foo2; switch (fn) { case fade : foo1 = fadeOut; foo2 = fadeIn;
<?php $var = 0; switch($var) { case a: echo I think var is a;
switch(ID) { case CustomReportsContainer: foreach (var report in SessionRepository.Instance.CustomReports.ToList()) { var reportItem = new
Here http://gplflash.sourceforge.net/gplflash2_blog/npapi.html Given code is switch(var) { case NPPVpluginNameString: *val = Example Plug-In; break;
Consider the following two snippets, with braces: switch (var) { case FOO: { x
for (var count = 1; count < 6; count++) { switch (count) { case
function parseAttach(b) { var h=; for(i=0;i<b.length;i++) { var a=b[i]; switch(a['type']) { case image: h+='<li
The following code passes JSLint: var sGreeting = 'hello world'; switch (sGreeting) { case
function openFile(file) { var extension = file.substr( (file.lastIndexOf('.') +1) ); switch(extension) { case 'jpg':

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.