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 1108167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:02:25+00:00 2026-05-17T02:02:25+00:00

Heres an interesting issue, I’m trying to check if a LINQ Entity exists in

  • 0

Heres an interesting issue, I’m trying to check if a LINQ Entity exists in its table, but at design time I dont know what type that entity is. So I figure I’ll just get the table, and try the Contains method on it. But I cant get the table in such a way that I can query it at design time.

I’ve tried the GetTable method on the datacontext, but I dont know how to cast it to the appropriate type when using GetTable(Of). GetTable(Type) works, I just use Entity.GetType(), but then I don’t know how to query the ITable thats returned.

To try and cast the ITable to something useable, I created an interface(IWhatever) that could implement properties that are native to all of my entities I would encounter. I then attempted a CType(GetTable(Entity.GetType()), IEnumerable(Of IWhatever))) No luck.

Any ideas, or am I just going about this completely wrong?

Example:

Public Function EntityExists(ByVal Entity As Object, ByVal DataContext As MyDataContext) As Boolean
    Dim T as Type = Entity.GetType()

    Dim EntityITable as ITable = DataContext.GetTable(T)

    'Do something to see if ITable contains Entity    

End Function
  • 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-17T02:02:26+00:00Added an answer on May 17, 2026 at 2:02 am

    I don’t know the vb.net syntax, so I’ll have to do this is C#:

    public bool EntityExists<T>(T Entity, MyDataContext DataContext)
    {    
        ITable<T> EntityITable  = DataContext.GetTable<T>();
        return EntityITable.Contains(Entity);
    } 
    

    The Vb.net, I imagine, would be something like:

    Public Function EntityExists(Of TEntity)(ByVal Entity As TEntity, _
                     ByVal DataContext As MyDataContext) As Boolean 
    
        Dim EntityITable as ITable(of TEntity) = DataContext.GetTable(of TEntity)()
    
        Return  EntityITable.Contains(Entity)
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I faced a very interesting issue. I'm trying to set the focus on a
Interesting issue here, optimising some code but am having trouble with scope issues using
I am running into an interesting performance issue with Entity Framework. I am using
I have an interesting problem here I've been trying to solve for the last
I have an interesting issue today!! Basically I have two classes. public class A
I just came across a very interesting issue. If I use ViewData to pass
Ok, so I was having a very interesting issue with CakePHP 1.3, in that
I'm having an interesting issue with Leptonica that I'm wondering if other SO members
I have a very interesting issue with only specific IE implementations. I have an
I have an interesting issue with inserting rows of data into a dataview. I

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.