A
Andrus
I have lot of sqlmetal generated entity types containing StartsWith method:
public class EntityBase { }
public class Customer : EntityBase {
public string Name { get; set; }
public static IQueryable<Customer> StartsWith() {
Northwind db = new Northwind(connStr);
var q = from c in db.Customers
where c.Name.StartsWith("A%")
select c;
return q;
}}
public class Supplier : EntityBase {
public string Name { get; set; }
public static IQueryable<Supplier> StartsWith() {
Northwind db = new Northwind(connStr);
var q = from c in db.Suppliers
where c.Name.StartsWith("B%")
select c;
return q;
}}
I want to create single wrapper method for them with signature
EntityBase[] StartsWith( string lookupEntityTypeName )
I can use
static class EntityManager {
static EntityBase[] StartsWith( string lookupEntityTypeName ) {
switch (entityTypeName) {
case "Customer":
return Customer2.StartsWith().ToArray();
case "Supplier":
return Supplier.StartsWith().ToArray();
......
}
}
}
This switch statement requires hard coding of all entity type names.
How to replace this with general solution which does not require hard-coding
type names ?
Andrus.
public class EntityBase { }
public class Customer : EntityBase {
public string Name { get; set; }
public static IQueryable<Customer> StartsWith() {
Northwind db = new Northwind(connStr);
var q = from c in db.Customers
where c.Name.StartsWith("A%")
select c;
return q;
}}
public class Supplier : EntityBase {
public string Name { get; set; }
public static IQueryable<Supplier> StartsWith() {
Northwind db = new Northwind(connStr);
var q = from c in db.Suppliers
where c.Name.StartsWith("B%")
select c;
return q;
}}
I want to create single wrapper method for them with signature
EntityBase[] StartsWith( string lookupEntityTypeName )
I can use
static class EntityManager {
static EntityBase[] StartsWith( string lookupEntityTypeName ) {
switch (entityTypeName) {
case "Customer":
return Customer2.StartsWith().ToArray();
case "Supplier":
return Supplier.StartsWith().ToArray();
......
}
}
}
This switch statement requires hard coding of all entity type names.
How to replace this with general solution which does not require hard-coding
type names ?
Andrus.