I have an existing database (which I cannot modify in any way) that I'd like to use EF to code against. There are no primary keys, foreign keys or actual relationships between tables - everything seems to be handled by applications using the DB. For most of the tables/entities, this has been trivial. However, I've got one class, like the one below (simplified) that I'm struggeling with.
[Table("tableName")]
public class MyClass
{
[Key]
[Column("id")]
public int? Id { get; set; }
[Column("name")]
public string CompanyName { get; set; }
[Column("address")]
public string Address { get; set; }
}
Things like _context.MyClasses.Where(x => x.Address == "something") work fine. However, it seems that when the id column is NULL in the DB, i get a null object back - even though CompanyName and Address have values. And I need those values, regardless of whether id (or whatever else) is null. Is there some way to force EF to generate the objects and ignore empty columns?
Removing or movin the [Key] attribute gives me an exception like "Must have a key column" (and the Id-column is also used to map a collection of other classes into this one if there are any that match).
UPDATE Don't think about the Id-column as an actual identifier. It's basically just an integer with a stupid name.