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
Customer is a table and "Customer" is one of the column in that table, When I create EDMX out of this table, "Customer" field suffixed with 1 (Customer1).
any specific reason?
can we rename column name as "Customer" instead.
Its a limitation of the language, no, you can't rename it Customer. A class cannot contain a property or field with the same name of its containing type. So the EDMX designer adds the 1 at the end.
Why is this? Think about constructors and finalizers, they are special methods that have the same name as the containing type. If you have a property with the same name, the compiler will not be able to resolve the constructor because you can't overload a property with a method.
Either pick a better name for the table (Customers) or the field.
Related
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 2 years ago.
Improve this question
I'm trying to help someone out and this isn't my area of expertise so thought maybe someone can help me help someone else.
I have a field called Master that contains an array. I also have a field called Original that contains a string. I want to check if the string in Original is in the array field called Field1 and then with an if statement do something if true / false
"Original":"1234",
"Master":[{"ID":1,"Field1":12345},
{"ID":2,"Field1":123456},
{"ID":3,"Field1":1234},
{"ID":4,"Field1":12344}]
The array can be different each time and have a different amount of records in it.
Can anyone help me?
if Original and Master would be properties of the same class and in a variable named instance then you could use Linq to do:
bool isPresent = instance.Master.Any(entry => entry.Field1 == instance.Original);
Obviously you would need to first serialize the json to an instance of this class.
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 5 years ago.
Improve this question
I'm trying to programming an schedule in C# where I want to show all my tasks, for example:
01-20-2018 at 3pm meeting with boss. And have a question:
Should I create a table "task" where i save the date my id and boss id?
Would it overload the dB?
I need some tips, thank you!
How many interlocutors (bosses) will you have ? Certainly more than one.
I suggest you should have one table for each purpose :
A task_table for tasks with an ID_Task as primary key, Detail field, delay field, status field and son on.
A target_table for the targets which is/are involved in the task with an ID_target (primary key) with a name field, first name field, company field, observation field and whatever field you need.
And you link this two tables in an another one :
Rendezvous_table, with Id_rendezvous (primary key), datetimestamp field, Id_Task field, Id_target field and observation_field for observation on rendezvous.
This can be a good start. Beware the relations one to multiple, one to one, multiple to multiple. Multiple task for a same rendez-vous, only one interlocutor for one rendez-vous or multiple...
Hope it helps.
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 6 years ago.
Improve this question
Let's suppose we have 2 tables:
Person
ID
Name
Nationality_ID (FK)
Nationality
ID
Name
With EF, in what contexts does it make sense and is correct to use each of the options below to add a nationality to a person? What is the different between them? What is the faster and the slower?
Option 1:
TheNationality.persons.Add(ThePerson);
Option 2:
ThePerson.nationality_id = TheNationality.id;
Option 3:
ThePerson.nationality = TheNationality;
If Person is the root of your aggregate and the focus of your application, most likely option 2 and option 3 make sense. Of those, option 3 is the more useful if you need to do additional domain logic based upon information in your nationality. Option 1 makes sense if the focus of your application is about nationality.
None of these methods is mutually exclusive. If you query and manipulate the objects from both perspectives, you can use options 1/3 or 1/2.
The resulting insert/update would be the same in all cases. Unless it is necessary to get TheNationality entity for some other reason, you could skip the read to obtain that and just assign the ID if you have it:
ThePerson.nationality_id = someNationalityIDVariable;
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 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 8 years ago.
Improve this question
I try to get column property's value by using entity framework in c#.
My Code:
foreach (var columns in _context.Properties)
{
var SelectedColumnValue = columns.GetType().GetProperties().GetValue(0)GetType();
}
How can i get value of propert(fieldname/column name) in entity framework ?
Any help will be appreciated.
Thanks
I don't know where to start. If _context is of type DbContext, Properties wouldn't have worked unless you have a table named Properties. So _context is probably typeof(DbContext). Then again, Type class does not have a property named Properties but it has the GetProperties() method.
In that case, each columns would be an instance of PropertyInfo. Then you could have used columns.Name to get the name of that property. Those names would have nothing to do with columns, but they would probably be pluralized names of tables.
tl;dr
I'm lost.