Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I've got the following model class:
public class Product
{
public int ProductID {get;set;}
public string ProductName {get;set; ]
public int ActiveOrdersCount {get;set;}
public Category[] Categories {get;set}
//etc...
}
When I load a product from the database, I load all the properties and maybe lazy-load the categories.
Does it make more sense to load all the properties of the object or partial etc?
It depends on how the objects will be accessed at run time. If you want to immediately access the categories collection for all of the products in a collection, then lazy loading will be very chatty.
On the other end of the spectrum if you only want to hit the Categories property for a small subset of the returned values, lazy loading might be beneficial.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 months ago.
The community reviewed whether to reopen this question 2 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
What is the best practice to define a One-to-Many relationship in EF Core?
Is it recommended to generally use lists, as these offer more functionalities?
Then rather the interface IList instead of List, as it does not define the implementation?
If it does matter, on what criteria should I pick one or the other?
Microsoft suggests the following
https://learn.microsoft.com/en-us/ef/core/modeling/relationships
public class Blog
{
public int BlogId { get; set; }
public List<Post> Posts { get; set; }
}
public class Post
{
public int PostId { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
Whereas
http://www.entityframeworktutorial.net/efcore/configure-one-to-many-relationship-using-fluent-api-in-ef-core.aspx
https://www.learnentityframeworkcore.com/configuration/one-to-many-relationship-configuration
suggest ICollections
Is the following answer of 2011 still valid in EF Core?
https://stackoverflow.com/a/7655974/10148774
Your decision should depend on the operations that your use case will need.
In general, you have three main options:
IEnumerable<> for a list of objects that only needs to be iterated through (no additional operations such as modifications).
ICollection<> for a list of objects that needs to be iterated through and modified.
IList<> for a list of objects that needs to be iterated through, modified, sorted, access by index...
Now this may lead you to the following question: "So I will always use List because it provides the most functionality". In this case you should keep in mind that this option has the most overhead and a good object-oriented practice is to program towards the interface and not the implementation. Implementations can and will change.
Long story short: There is no golden rule here, you need to analyze and make the proper trade-offs for your specific scenario in order to make the best choice.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a class called Promotion (model class). I want a promotion to have a type called Category where Category is its own model class I'm assuming where I would define all the types of categories such as fast food foot wear jewelry and so on. I'm not quite sure of how to go about this though so for example, my class called category is already a set thing but my class promotion is something where before I create it I need to set it with a category with the viable category options. thank you!
why don't you create a property called Categories of type Category in the Promotion?
enum Algorithms
{
FCFS,
SJF,
PRIORITY,
RR
}
class Process
{
public Algorithm algorithms{get;}
}
For the detailed difference please read the answer from this SO answer
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
https://www.youtube.com/watch?v=K1xrlc32Tmw&list=PLJUoF2h8Z-brW94dTZ-ZIOhjFq90_lt5K&index=9
4:25 adds a new object in the lineCollection if product does not exist in lineCollection, but at 24:25 it shows duplicating orders? Did i misunderstood how it works?
https://github.com/jedjad/GitHubVS2013
Because the products in duplicate values are not same objects. They may have same names, quantity etc, but initializing a class with same values does not mean that it is the same object as the one initialized before. They are like 2 different apples with same color and size.
If you say that 2 products are same whenever the names are same, then implement IEquatable<Product> in Product class.
public bool Equals(Product other)
{
return Name == other.Name;
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
If a partial class has the same method name but different types I will get an error right?
public partial class Employee
{
public int sum()
{
}
}
public partial class Employee
{
public string sum()
{
}
}
Yes, it does:
'Employee' already defines a member called 'sum' with the same parameter types
Partial classes are just the same as regular class, except their definition is split in two sources. They have to comply to every rule regular classes have. That includes rules concerning the uniqueness of method signatures.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have a search form that allows users to search real estate listings.
I currently have it set up as a basic html form that posts to a search results page.
On the search results page, I then use raw SQL and query the database and then use a repeater to display the results. I also create session variables on the query so if the user does another search they dont have to fill out the whole search, just edit it.
I was wondering if I should rather create a search class with a search object that gets created and edited with each search. Is this the best practice? or is my method above sufficient?
Thanks!
If there are lots of search parameters then I'd create a class to encapsulate them all and store that in session state, rather than maintaining lots of separate session variables. You might need to decorate this class with the SerializableAttribute depending on how you've got your session state configured, e.g.
[Serializable]
public class SearchOptions
{
public string Foo { get; set; }
public string Bar { get; set; }
}