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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:22:28+00:00 2026-05-25T00:22:28+00:00

I have three entities in my data context which inherit IFileData , but I

  • 0

I have three entities in my data context which inherit IFileData, but I want just a single delete method. How can this be achieved?

The code below give the error The type "IFileData" is not mapped as a Table.

    public void ImageDelete<T>(T instance) where T : class, IFileData
    {
        using (var db = this.CreateDataContext())
        {
            db.GetTable<T>().DeleteOnSubmit(instance);
            db.SubmitChanges();
        }
    }

The only solution I have so far is to do a switch on the .GetType() which is a bit messy.

Thanks!

Solution:

As Marc mentioned, I used dynamic in the calling method:

ImageDelete((dynamic)(instance as IFileData));

  • 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-25T00:22:28+00:00Added an answer on May 25, 2026 at 12:22 am

    You could build the Expression manually, using the actual T ? Untested (since that Delete doesn’t exist?), but something like:

    var param = Expression.Parameter(typeof(T), "x");
    var lambda = Expression.Lambda<Func<T, bool>>(
        Expression.Equal(
           Expression.Property(param, "Key"),
           Expression.Constant(instance.Key)
        ), param);
    

    This then isn’t bound to IFileData, but to T. It will fail, however, if IFileData.Key is implemented via explicit interface implementation – there must be an obvious Key field/property on T.

    Then:

    var table = db.GetTable<T>();
    var obj = table.SingleOrDefault(lambda);
    if(obj != null) table.DeleteOnSubmit(obj);
    db.SubmitChanges();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three entities. Author Newspaper Dissertation Newspaper and Dissertation both can have one
So I've got some data. There are entities. Entities have an arbitrary number of
I have three entities: EntityA, EntityB and EntityC connected with to-many relationships. See schema
I have a case where i have three entities with one-to-many and one-to-many relationships:
Have three divs in a container that I want to float over a large
all my entities have a common property which specifies the company they belong to,
I have an iPhone/iPad app which uses Core Data. In my DB I have
I have three tables: Context, Component and ComponentContext. The ComponentContext table links the Component
I'm having problem how to formulate NSPredicate to get correct data. I have three
I have some code which returns InnerXML for a XMLNode. The node can contain

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.