Maybe was a mistake from me that I posted my replies to your message. My replies was intend to be a general replies to all of those that have down voted. Because I think each down vote should have an argumentation. And I found the answer elsewhere ( it is not my solution ) , but I don't post here only for those that have down voted. ( if you are one of them , this is for you too). The reason is that I think that when someone doesn't know the solution , attack the question. For these people I thing that they aren't professional. Instead of simply down vote a question : 1) Find a solution 2) Ignore the question 3) Say " I'm sorry I don't know " 4) Down vote , but with arguments why this question has problems.
dilkonika
Posts
-
Continue to next step in a for..next loop only when the user press a button. -
Continue to next step in a for..next loop only when the user press a button.and what is the abusive part of my post ? If you are one of them that down voted , well , sometimes the truth is hard to accept.:confused:
-
Entity framework : How to get DBcontext.ChangeTracker.Entries(of ???)) for a class known only at runtimeI'm using entity framework I'm trying to make a general function that works for an object for which the class is known only at runtime. I have an instruction that use an expression similar to this :
context.ChangeTracker.Entries(of Myobj1)
Of course that if I know the class name "MyObj1" the above expression is working correctly. But at runtime , I only have an variable :
Dim tp as type
which contain the class , and i need an expression like this :
context.ChangeTracker.Entries(of tp)
Thank you !
-
Continue to next step in a for..next loop only when the user press a button.Thanks to all for your down Votes. It's seems that those who doesn't have the idea how to resolve the problem , attack the question. Sorry friend what do you want , to ask : " ... It's true that 1+1=2 ?" It's sure that for this question exist a solution ( even prior to .NET 4.5 ) ( for sure , it's not me that found the solution , because I don't pretend to be a high level professional ). But I will not post here the solution. Maybe some of those that have down voted , try to find the answer , because someone that pretend to have a professional level , should show this with an answer not with a down vote.
-
Continue to next step in a for..next loop only when the user press a button.Ok , I give you some additional details : I'm using the form to edit , create and modify records form a database. The button for which I'm talking has all the necessary code to test the new record created by user , and if the test is done without problems , the new record is saved. But this button can test and save records one by one ( so if a user create a new record , he should press the button before create another ). Now , I have added a new function in my form : Copy paste records. So the user can select one ( or several ) existing records , and press copy on the right click menu. When a copy is made , a list is created that contains all the records that are copied and should be pasted. for the Paste actions , I have this For..next loop. But the records that are copied , should be pasted one by one. So a new record is created that is a copy of the first element on the copy-list. At this point , the loop should stop , and user can make the changes needed for this copy and after should press the button to do the actions needed and to save this record. After the loop can continue with the same logic for the other records. This is all. Can you give me a new idea ? Thank you !
-
Continue to next step in a for..next loop only when the user press a button.sorry , but could you tell me what is the response that should I accept ? Until now in the answers I read only words. I think that if someone doesn't know an idea about the response is better not to respond ( as is happen for some of my other recent questions where nobody has given a single response. )
-
Continue to next step in a for..next loop only when the user press a button.Ok , I'm ready to accept any other solution , but first let explain something : In the form I have this button. This button do some actions. and may be enable on several situations . so this button does not depend on the for..Next loop. so even the For..next loop will be never executed , the code inside the button may be executed on several occasions when the user press the button. The for ..next loop is on another sub , that when is executed , sometimes can make the button enabled. On this cases , the loop should wait until the user press that button and after continue to next step. What are your new solutions to resolve this case ? Thank you !
-
Get the primary key property name and the Foreign key property name of an arbitrary entityFor the Primary key :
Public Function Get_PK(ctx As MyEntities, entity As Object) As String
Dim objectContext = DirectCast(ctx, System.Data.Entity.Infrastructure.IObjectContextAdapter).ObjectContext
Dim t As Type = entity.GetType.BaseType
Dim m As MethodInfo = objectContext.GetType().GetMethod("CreateObjectSet", New Type() {})
Dim generic As MethodInfo = m.MakeGenericMethod(t)
Dim st As Object = generic.Invoke(objectContext, Nothing)
Dim entitySetPI As PropertyInfo = st.GetType().GetProperty("EntitySet")
Dim entitySet As Metadata.Edm.EntitySet = DirectCast(entitySetPI.GetValue(st, Nothing), Metadata.Edm.EntitySet)
Dim keyNames As IEnumerable(Of String) = entitySet.ElementType.KeyMembers.[Select](Function(k) k.Name)
Return keyNames(0)
End FunctionFor the Foreign key :
Public Function Get_FK(ctx As MyEntities, entity As Object, parenttable As String) As String
Dim objectCont = DirectCast(ctx, System.Data.Entity.Infrastructure.IObjectContextAdapter).ObjectContext
Dim t As Type = entity.GetType.BaseType
Dim m As MethodInfo = objcont.GetType().GetMethod("CreateObjectSet", New Type() {})
Dim generic As MethodInfo = m.MakeGenericMethod(t)
Dim st As Object = generic.Invoke(objcont, Nothing)
Dim entitySetPI As PropertyInfo = st.GetType().GetProperty("EntitySet")
Dim entitySet As Metadata.Edm.EntitySet = DirectCast(entitySetPI.GetValue(st, Nothing), Metadata.Edm.EntitySet)
Dim elementtype = entitySet.ElementType
Dim entitymember = elementtype.NavigationProperties.Where(Function(t1) t1.ToEndMember.Name = parenttable)
Return entitymember.First.GetDependentProperties.First.Name
End FunctionPlease give me some reputation , because I found the answer ;P
-
Continue to next step in a for..next loop only when the user press a button.I think you misunderstand what I mean with my words. I mean that someone can't give an opinion that should I use or not an For..Next loop because he don't know all the logic of my program. So why you want to comment the question instead of try to give a response. The question is very clear. If there's no answer , respond "it's not possible.". And about the reputation , I'm not interested , because I'm more interested about the answers of my questions.
-
Continue to next step in a for..next loop only when the user press a button.I described a case when I already have a for loop. And if in one step of this loop , the button became enabled , the loop should be stopped , and to go to to the next step the user should press the button. If the condition is always false , the for loop should continue until the end without interruption. This is my case. Is there any solution for this case ? Thank you ! ( I'm not asking if there's another way to do , because you can't give an opinion since you don't know nothing about my program , except the little part that I have described here)
-
Continue to next step in a for..next loop only when the user press a button.I described my problem in my post. So I need response for the case when I need a for loop.
-
Continue to next step in a for..next loop only when the user press a button.I'm using vb.net , and I have this situation : I have a button on the form( Mybutton1 ) . I have also a sub that contains a for..next loop :
.....
for I=1 to nr1
{.... some instructions...}
if condition1 then Mybutton1.enable=true
NextOn every step of this For loop , the button became enabled when a condition is true .In this case I want that this loop to stop until the user press the Button. ( the button's click event , at the end has some instructions that makes the button disabled again ) Is there any way to do this behavior ? Thank you !
-
How to get the item's data type in an bound Bindingsource that actually is empty?I have a bindingsource bound to an entity. When the bindingsource has at least one item , I can get the item's data type with :
MyBindingSource.Current.GetType
But how can I do in the case when bindingsource has no items ? I try this :
MyBindingSource.GetItemProperties(Nothing)(0).ComponentType
But doesn't work. Thank you !
-
Get the primary key property name and the Foreign key property name of an arbitrary entityHello ! I'm using entity Framework (Database First ) with a SQL Server Database. I have a situation where I have an object ( that is an entity object ) , but the type is known only on runtime ). I need to get the Primary key property name and the Foreign key property name ( for a specific relation) for example MyObj (ObId , name , val1)------- ( ObID is primary key ) MyChild (ChlID ,dt , MyObj_ID) --- ( CHLID is primary Key , Myobj_ID is foreign key) Dim obj1 ..... Get_PK(obj1) I want that the possible function Get_PK to return a string with the value : - "ObID" ( if the type of the object is MyOBJ) , or "ChlID" if the object is of the type MyChild. and the function Get_Parent(obj1,chl1) to return "MyOBj_ID" But of course it must be a general function that works with every class inside the entity. Actually I have 2 functions :
Public Function Get_pk(ctx As MyEntities, entity As Object) As String
Dim objectContext = DirectCast(ctx, System.Data.Entity.Infrastructure.IObjectContextAdapter).ObjectContext
Dim t As Type = entity.GetType.BaseType
Dim m As MethodInfo = objectContext.GetType().GetMethod("CreateObjectSet", New Type() {})
Dim generic As MethodInfo = m.MakeGenericMethod(t)
Dim st As Object = generic.Invoke(objectContext, Nothing)
Dim entitySetPI As PropertyInfo = st.GetType().GetProperty("EntitySet")
Dim entitySet As Metadata.Edm.EntitySet = DirectCast(entitySetPI.GetValue(st, Nothing), Metadata.Edm.EntitySet)
Dim keyNames As IEnumerable(Of String) = entitySet.ElementType.KeyMembers.Select(Function(k) k.Name)
Return keyNames(0)
End FunctionThis is for Primary Key property , and is working , but is is slow ( I'm thinking if Entity framework has a built in method to get this directly ??? )
Public Function Get_FK(ctx As MyEntities, entity As Object, parenttable As String) As String
Dim fk = entity.MetadataWorkspace.GetItems(Of Metadata.Edm.AssociationType)(Metadata.Edm.DataSpace.CSpace).Where(Function(a) a.IsForeignKey)
Dim fkname = fk.Where(Function(x) x.ReferentialConstraints(0).ToRole.Name = parenttable)
Dim refcol = fkname.Select(Function(x) x.ReferentialConstraints(0).FromProperties(0).Name).First()
return refcol
End FunctionThis is for the foreign key (related with a parenttable that is passed as parameter ). This is not working. I get an error in the first line because entity is a proxy object
-
Create a list of Unknown type at compile timeok. I need a way to detect that this list is empty. But the expression that should do this , must include 2 cases : - The list is not yet created . ( So it's just declared as mylist as Ilist). - The list is created ( with your code ) but the items are deleted ( or has no items ). I try with the code : If mylist.Count..... but this doesn't work.
-
Create a list of Unknown type at compile timeI add :
Imports System.Collections
and now the errors are resolved. But I have some problems in runtime 1. I want first to initialize an empty list. Because if I have just the :
dim itemlist as Ilist
( Before calling these 2 lines
Dim customList As Type = GetType(List(Of )).MakeGenericType(GetType(MyClass))
itemlist = CType(Activator.CreateInstance(customList), IList)How can I check if the list is empty or ?? something similar. But I want a general checkin mode , because the same expression must be correct even when I clear the list and I want to check if empty ( before initializing for a new type ). ( I try to use
If itemlist.Count > 0 Then
but doesn't work.
-
Create a list of Unknown type at compile timeYes , Ilist and Ienumerable are unknown and produce a similar error message that I have posted before.
-
Create a list of Unknown type at compile timesorry , but the Ilist type is unknown . Everytime I get an error that :
Error 103 Too few type arguments to 'System.Collections.Generic.IList(Of T)'
I don't know why ?
-
Create a list of Unknown type at compile timeI don't know c# , so I have used a code translator. this is the code :
Dim customList As Type = GetType(List(Of )).MakeGenericType(tempType)
Dim objectList As IList = CType(Activator.CreateInstance(customList), IList)' Copy items from a PropertyInfo list to the object just created
Dim o As Object = objectThatContainsListToCopyFrom
Dim p As PropertyInfo = o.[GetType]().GetProperty("PropertyName")
Dim copyFrom As IEnumerable = p.GetValue(o, Nothing)
For Each item As Object In copyFrom
objectList.Add(item)
Next
' Will throw exceptions if the types don't match.
' Iterate and access the items of "objectList"
' (objectList declared above as non-generic IEnumerable)
For Each item As Object In objectList
Debug.WriteLine(item.ToString())
NextIt shows several errors , but the first is on second line :
Error 103 Too few type arguments to 'System.Collections.Generic.IList(Of T)'
-
Create a list of Unknown type at compile timeHello ! It's possible to create a list of unknown type at compile time ? Let's suppose the type is in one variable as a string. And I want to create a list of this type , and of course after I want to add items from this type to the list. I have found this code on C# , but it seems not work on vb.net :
// Create a List<> of unknown type at compile time.
Type customList = typeof(List<>).MakeGenericType(tempType);
IList objectList = (IList)Activator.CreateInstance(customList);// Copy items from a PropertyInfo list to the object just created
object o = objectThatContainsListToCopyFrom;
PropertyInfo p = o.GetType().GetProperty("PropertyName");
IEnumerable copyFrom = p.GetValue(o, null);
foreach(object item in copyFrom) objectList.Add(item); // Will throw exceptions if the types don't match.// Iterate and access the items of "objectList"
// (objectList declared above as non-generic IEnumerable)
foreach(object item in objectList) { Debug.WriteLine(item.ToString()); }I just want to create the list , and after to add items like this :
List1.Items.Add(object).
What can I do ? Thank you !