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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:06:15+00:00 2026-06-15T21:06:15+00:00

I come from a PHP/MySQL background, so maybe the problems I’m having with .NET

  • 0

I come from a PHP/MySQL background, so maybe the problems I’m having with .NET stem from that. After a week of posting how to create an inventory tracker for our computer hardware and software, someone finally told me that he thought I was doing things wrong. The issue was not my code, but my design. That’s certainly possible. I’m trying to do this in EF Code First and the idea of generating a database with code is foreign to me. However, I got the database working and everything was pointing to the right thing. But I can’t pull what I need from the database.

What I want to do is create a dashboard page that would have categories for the types of hardware. So there would be a list of PCs, a list of monitors, a list of printers, etc. Initially, what I did was based on my knowledge of MySQL. I created a Hardware table (class) and a HardwareTypes table (class). In MySQL, what I would have done is put the ID for the HardwareType in the Hardware table, so I could do joins. Then I can get all of my PCs with a simple inner join.

.NET seems like it’s different. It wants to create an intermediate table — HardwareHardwareTypes, and then connect the two other tables. That seems strange, but OK. But when I go to get all of my PCs, I can’t seem to get the help I need to write the query. So please take a look at my query and my classes, and let me know your thoughts.

Query, which returns Hardware, not HardwareTypes — how do I get HardwareTypes?):

var pcs = db.Hardware.Where(h => h.HardwareType.Any(hwt => hwt.HType == "PC"));
ViewBag.Pcs = pcs.ToList();

Hardware class:

public class Hardware
    {
        public int Id { get; set; }
        public virtual ICollection<DeviceType> Type { get; set; }
        public string AssetTagId { get; set; }
        public virtual ICollection<Manufacturer> Manufacturer { get; set; }
        [Required]
        [StringLength(50)]
        public string ServiceTagId { get; set; }
        [Required]
        [StringLength(50)]
        public string SerialNumber { get; set; }
        [Required]
        [StringLength(75)]
        public string ProductNumber { get; set; }
       // [Required]
        [StringLength(20)]
        public string PurchaseDate { get; set; }
        [StringLength(20)]
        public string WarrantyExpiration { get; set; }
        [Required]
        [StringLength(20)]
        public string WarrantyType { get; set; }
        public virtual ICollection<Location> Location { get; set; }
        public virtual ICollection<HardwareType> HardwareType { get; set; }
        [Required]
        [StringLength(2000)]
        public string Notes { get; set; }
        public string POATag { get; set; }
    }

HardwareTypes class:

public class HardwareType
    {
        public int Id { get; set; }
        [Required]
        [StringLength(128)]
        public string HType { get; set; }
        public virtual ICollection<Hardware> Hardware { get; set; }
    }

Again, if what I need is more of a high-level design change, please let me know. If I need a different query, let me know that. The third (intermediate) table is dynamically generated and it’s hard to know how to post that. I’d appreciate any and all help with this. What I need in the end is a list of PCs. Here is some sample seed data:

    ... new Hardware { AssetTagId = "2134", 
Type = device.Where(h => h.DType == "Network Device").ToArray(), 
Manufacturer = manuf.Where(h => h.ManufacturerName == "SonicWall").ToArray(), 
ServiceTagId = "5243", 
SerialNumber = "3456", 
ProductNumber = "2345", 
PurchaseDate = "2012-10-23", 
WarrantyExpiration = "2012-11-12", 
WarrantyType = "NBD", 
Location = loc.Where(h => h.LocationName == "Paradise Lane").ToArray(), 
Notes = "Scrapped",  
HardwareType = htype.Where(h => h.HType == "PC").ToArray()}, ...

 var htype = new List<HardwareType> {
                new HardwareType { HType = "PC" },
                new HardwareType { HType = "Monitor" },
                new HardwareType { HType = "Printer" },
                new HardwareType { HType = "Miscellaneous" }
            };

If my seed data is structured wrong, please let me know that. Thanks.

  • 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-06-15T21:06:16+00:00Added an answer on June 15, 2026 at 9:06 pm

    Let me tell you first of all that the same database design which works in PHP/MySQL can work here also.

    The easiest approach I will suggest to you is to create a view in the database which joins table Hardware and HardwareType, add nwly created view to you database model and fetch the desired data from the view instead of tables.

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

Sidebar

Related Questions

I'm not too used to ORM mapping, having come from a PHP background. I'm
I come from a linux/apache/php/mysql background. For my current project, I am forced to
I come from PHP background and am used to doing var_dump , echo and
I come from a php background and in php, there is an array_size() function
I come from a PHP background and I'm just getting my teeth into some
I come into ASP.NET from php so the reason why i ask my question
I'm new to PHP but come from a Java background and I'm trying to
I come from a Java background and am getting more into .NET, what are
I come from a SQL Server background and thought that it might mean it
I am new to PHP scripting and come from Java background. Here is a

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.