I have 3 classes PropiedadEspecificaFilm, PropiedadEspecificaBook and PropiedadEspecificaMusic which inherit from Product.
public partial class PropiedadEspecificaBook : Product
{
public string ISBN { get; set; }
public string author { get; set; }
public long productId { get; set; }
//Equals
//ToString
}
public partial class PropiedadEspecificaMusic : Product
{
public string name { get; set; }
public string artist{ get; set; }
public long productId { get; set; }
//Equals
//ToString
}
public partial class PropiedadEspecificaMusic : Product
{
public string name { get; set; }
public string artist{ get; set; }
public long productId { get; set; }
//Equals
//ToString
}
public partial class Product
{
public Product()
{
this.OrderLines = new HashSet<OrderLine>();
this.Comments = new HashSet<Comment>();
}
public long id { get; set; }
public string productName { get; set; }
public decimal price { get; set; }
public System.DateTime releaseDate { get; set; }
public short stock { get; set; }
public long categoryId { get; set; }
}
Is there a way to know which one of the PropiedadEspecifica has the productId I am looking for?
Yes, if all products share a property you should declare that in the parent class and not in the children. The children should only have the properties that differ from the parent class.
I also strongly suspect you do not need to mark your classes as partial (that is used if you want to split your class definition up, it is not intended for inheritance).
I also changed so the public properties are capitalized since that is the general convention for c# naming.
public class PropiedadEspecificaBook : Product
{
public string ISBN { get; set; }
public string Author { get; set; }
}
public class PropiedadEspecificaMusic : Product
{
public string Name { get; set; }
public string Artist{ get; set; }
}
public class PropiedadEspecificaMusic : Product
{
public string Name { get; set; }
public string Artist{ get; set; }
}
public class Product
{
public Product()
{
this.OrderLines = new HashSet<OrderLine>();
this.Comments = new HashSet<Comment>();
}
public long Id { get; set; }
public string ProductName { get; set; }
public decimal Price { get; set; }
public System.DateTime ReleaseDate { get; set; }
public short Stock { get; set; }
public long CategoryId { get; set; }
public long ProductId { get; set; }
}
I solved it by adding a virtual Dictionary<String, String> FindPropiedadEspecificaMethod() in Product. And then Overriding in each PropiedadEspecifica. Sorry because the problem was bad explained.
Related
I have Domain object ProductType. It contains parentproducttypeId column. If product type is a subset of another producttype that parentproducttypeId to set to that producttypeId.(ex: T-Shirt is a subset of Casual wears)
public class ProductType : IEntityBase
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int PerentProductTypeId { get; set; }
public int Active { get; set; }
public DateTime UpdatedOnUTC { get; set; }
}
In API view model I have two classes
public class ParentProductTypeModel
{
public int Id { get; set; }
public string Name { get; set; }
public List<ChildProductTypeModel> ChildProductTypeList { get; set; }
public ParentProductTypeModel()
{
ChildProductTypeList = new List<ChildProductTypeModel>();
}
}
public class ChildProductTypeModel
{
public int Id { get; set; }
public string Name { get; set; }
}
I need to Map returned List of Product Type to this ParentProductTypeModel List with setting all subset lists according to there parentproducttypeId. If parentproducttypeId equals to 0 it is parentproduct.
I have been reading about Entity Framework during the pass few weeks. I came across TPT subject. I am a little bit confused and have difficulty to differentiate between TPT and Navigation. When should we choose one over another. Please take a look at the code below.
A. Navication
public class Employee
{
public int EmployeeId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Gender { get; set; }
public List<ContractEmployee> ContractEmployees { get; set; }
public List<PermanentEmployee> PermanentEmployees { get; set; }
}
public class ContractEmployee
{
public int HourlyWorked { get; set; }
public int HourlyPay { get; set; }
public Employee Employee { get; set; }
}
public class PermanentEmployee
{
public int AnnualSalary { get; set; }
public Employee Employee { get; set; }
}
B. TPT
[Table("Employee")]
public class Employee
{
public int EmployeeId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Gender { get; set; }
}
[Table("ContractEmployee")]
public class ContractEmployee : Employee
{
public int HourlyWorked { get; set; }
public int HourlyPay { get; set; }
}
[Table("ContractEmployee")]
public class PermanentEmployee : Employee
{
public int AnnualSalary { get; set; }
}
There is a model class called Review.
ReviewModel is used from StoreModel and Menu model.
In StoreModel.cs
[Table ("Stores")]
public class StoreModel
{
[Key]
public int Id { get; set; }
public string StoreName { get; set; }
public string StoreShortDescription { get; set; }
public string StoreFullDescription { get; set; }
public string StoreAddress { get; set; }
public ICollection<MenuModel> Menus { get; set; }
public ICollection<ReviewModel> Reviews { get; set; }
public StoreModel ()
{
Menus = new Collection<MenuModel> ();
Reviews = new Collection<ReviewModel> ();
}
}
in MenuModel.cs
[Table ("Menus")]
public class MenuModel
{
[Key]
public int Id { get; set; }
public string MenuName { get; set; }
public string MenuShortDescription { get; set; }
public string MenuThumbnailUrl { get; set; }
public int MenuPrice { get; set; }
public ICollection<ReviewModel> MenuReviews { get; set; }
public MenuModel ()
{
MenuReviews = new Collection<ReviewModel> ();
}
}
In this case, how should I implement this?
Create a base ReviewModel class and have 2 subclass (StoreReview, MenuModel)
or
Use ReviewModel for both StoreModel and MenuModel (how?)
or
thoughts?
If the ReviewModel properties are the same in both (StoreModel and MenuModel) there is nothing special to do, just use ReviewModel as it is being used in your shown code for both models.
In any case, just add an enum property to ReviewModel to know wether it is a StoreModelReview or a MenuModelReview.
Your ReviewModel might look like this: (creating many 2 many relationship)
[Table ("Reviews")]
public class ReviewModel
{
[Key]
public int Id { get; set; }
public ReviewEnum Type { get; set; }
public ICollection<MenuModel> Menus{ get; set; }
public ICollection<StoreModel> Stpres{ get; set; }
}
I have a c# class as below
public class CreateStudent
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public int Age { get; set; }
}
and I need another class with following properties
public class EditStudent
{
public string Name { get; set; }
public string Address { get; set; }
public int Age { get; set; }
public DateTime Date_of_Birth { get; set; }
}
I have repeated properties except that one field (Date_of_Birth) is added in the EditStudent Model.
Is there an option to reuse some of the properties from previous CreateStudent model
I am going to handle these data as Json objects in my front end angularjs based application
You could do this with a null-able property.
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public int Age { get; set; }
public DateTime? Date_of_Birth { get; set; }
}
This way you only have one Student model that can accommodate both use-cases.
you should be using inheritance feature here.
public class CreateStudent
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public int Age { get; set; }
}
public class EditStudent : CreateStudent
{
public DateTime Date_of_Birth { get; set; }
}
I've been working on this for a while now and i still haven't come up with a good idea.
I have the fallowing 3 types Project, User and Result. A user and a project can have multiple results. My problem now is that a result can be of multiple types (12 right now and that can change). I have no idea how i'm supposed to structure this the only things that this results have in common is a type and an Id and i want a table for each of the different 12 types.
So what i have until now is this.
Project
public class Project :ITypedEntity<ProjectType>
{
public int Id { get; set; }
public string Name { get; set; }
public string Nationality { get; set; }
public virtual ProjectType Type { get; set; }
public string TitleEn { get; set; }
public string TitleRo { get; set; }
public string Acronym { get; set; }
public string ContractNo { get; set; }
public virtual ActivityField ActivityField {get;set;}
public string SummaryEn { get; set; }
public string SumarryRo { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public decimal Value { get; set; }
public bool IsPartner { get; set; }
public ICollection<User> Team{get;set;}
public string Website {get;set;}
public ICollection<INamedEntity> Results;
}
Result
public class Result:ITypedEntity<ResultType>
{
public int Id { get; set; }
public string Name{get;set;}
public ResultType Type { get; set; }
}
User
public class User:Person
{
public int CNP { get; set; }
public virtual Faculty Faculty { get; set; }
public bool IsUSAMV {get;set;}
public virtual ICollection<INamedEntity> Results {get;set;}
public virtual ICollection<Project> Projects {get;set;}
}
I don't think this helps but i'll paste them anyway
public interface INamedEntity:IEntity
{
string Name{get;set;}
}
public interface ITypedEntity<TType>:INamedEntity{
TType Type { get; set; }
}
public interface IEntity
{
int Id { get; set; }
}
Update 1
Some results types
public class BookChapter:INamedEntity
{
public int Id { get; set; }
public string Name { get; set; }
public virtual Book Book {get;set;}
public int PagesInChapter {get;set;}
public string Pagination {get;set;}
}
public class Book:INamedEntity
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Person> Authors { get; set; }
public int Year { get; set; }
public Publisher Publisher {get;set;}
public int NumberOfPages { get; set; }
public string Pagination { get; set; }
public int ISBN { get; set; }
}
public class Patent:ITypedEntity<PatentType>
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Person> Authors { get; set; }
public virtual Person Holder{get;set;}
public string Number{get;set;}
public virtual PatentType Type { get; set; }
}
Sorry if the question is not clear, i'll update it with any other information you need.
Thanks.