Finding field index from entity field name (adapter)?

Posts   
 
    
SaX
User
Posts: 42
Joined: 29-Apr-2004
# Posted on: 06-May-2004 11:37:03   

I'm trying to create a method that takes entity filed name as input parameter and uses field index of that field (for filtering). How do I find field index if I know filed name?

netclectic avatar
netclectic
User
Posts: 255
Joined: 28-Jan-2004
# Posted on: 06-May-2004 11:51:46   

You could use the Parse method of the enum, something like this should do it:

MYENTITYFieldIndex index = (MYENTITYFieldIndex)MYENTITYFieldIndex.Parse(typeof(MYENTITYFieldIndex), myFieldName, false);
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39612
Joined: 17-Aug-2003
# Posted on: 06-May-2004 12:14:03   

There is no 'easy' way I'm afraid. You can re-instantiate the enum type, grab the field index if you like, but the factories work with overloading, and the Enum methods return object, so it will not compile.

a couple of solutions:

pass along the entity enum value also, so you can create an EntityFields object, using the EntityFieldsFactory class. You'll get back an EntityFields object which accepts a string indexer, like this:

IEntityField field = (EntityFieldsFactory.Create(entityEnumValue))[fieldName];

You then have the field, and you can create FieldCompareValue objects for example, bypassing the predicate factory (which does the same thing: create an entity field object and then create the predicate objects).

Another solution could be that you set up a template which generates switch statements and returns per entity type teh enum value based on the field name.

Another solution could be that you re-instantiate an empty new entity, then grab the field through the indexer and create the fields.

If you need help with this, please post your code and your questions in this thread simple_smile

@Netclectic: I had that too, however I wasn't sure if he new the enum type simple_smile THanks for posting that simple_smile

Frans Bouma | Lead developer LLBLGen Pro
netclectic avatar
netclectic
User
Posts: 255
Joined: 28-Jan-2004
# Posted on: 06-May-2004 13:16:05   

Otis wrote:

@Netclectic: I had that too, however I wasn't sure if he new the enum type simple_smile THanks for posting that simple_smile

Yeah, i figured that could be a problem.

I ended up using something similar to the one you posted above:

IEntityField field = (EntityFieldsFactory.Create(entityEnumValue))[fieldName];

and i was able to use the int value of the FieldIndex property.

SaX
User
Posts: 42
Joined: 29-Apr-2004
# Posted on: 06-May-2004 13:42:36   

Thanks...

Shah
User
Posts: 6
Joined: 20-Oct-2005
# Posted on: 20-Oct-2005 23:44:08   

Hi folks, is somebody know how can I add multiple fields to a filter, but not by field's name, by field's index.

Let me explain.

I have tryed to design a search method and I want to give the users this capability to chose any field(s) in search patern. Then I had to do this:

for (int i = 0; i < vehicleEntity.Fields.Count; i++) { filter.Add(PredicateFactory.CompareValue( VehicleFieldIndex(i), ComparisonOperator.Equal, vehicleEntity.Fields(i)));}

inside the loop, I have tried to add muti fields to filter, but I know there is no way to say

VehicleFieldIndex(i), I have to say, for example, VehicleFieldIndex.VehicleName becase it retrive fields by name, and it doesn't let me to go by index.

any solution?

thanks,

Shah

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39612
Joined: 17-Aug-2003
# Posted on: 21-Oct-2005 15:17:08   

Shah wrote:

Hi folks, is somebody know how can I add multiple fields to a filter, but not by field's name, by field's index.

Let me explain.

I have tryed to design a search method and I want to give the users this capability to chose any field(s) in search patern. Then I had to do this:

for (int i = 0; i < vehicleEntity.Fields.Count; i++) { filter.Add(PredicateFactory.CompareValue( VehicleFieldIndex(i), ComparisonOperator.Equal, vehicleEntity.Fields(i)));}

inside the loop, I have tried to add muti fields to filter, but I know there is no way to say

Use: [code] for (int i = 0; i < vehicleEntity.Fields.Count; i++) { filter.Add( new FieldCompareValuePredicate(vehicleEntity.Fields[i], ComparisonOperator.Equal)); }

Frans Bouma | Lead developer LLBLGen Pro
Shah
User
Posts: 6
Joined: 20-Oct-2005
# Posted on: 25-Oct-2005 18:23:07   

Hi Otis, thanks for your solution.

I have one more question for you.

How do you use a IS Null operator or Like operator in sort Clause. When I use a this command

ISortExpression sortItems = new SortExpression( SortClauseFactory.Create(ItemFieldIndex.ItemDescription, SortOperator.Ascending));

it raise an error. Becuase I'm tring to sort a Text feild(ItemDescription). This is a error message:

The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception..

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39612
Joined: 17-Aug-2003
# Posted on: 26-Oct-2005 10:05:10   

You can't sort a text field. The error from SqlServer is misleading, it's an error they ALSO return when you do a compare. In THAT case, you can only compare with LIKE and IS NULL statements. So sorting on text is not possible in sqlserver.

Frans Bouma | Lead developer LLBLGen Pro
Shah
User
Posts: 6
Joined: 20-Oct-2005
# Posted on: 26-Oct-2005 14:03:41   

Actually, I talked to UI guys and I said it doesn’t make sense to have a sort on Text field, because ms sql retrieve those fields as BLOB and doesn’t let to sort them.

Any way appreciates.

Shah
User
Posts: 6
Joined: 20-Oct-2005
# Posted on: 26-Oct-2005 14:16:19   

I got it. Actually, I talked to UI guys and I said it doesn’t make sense to have a sort on Text field, because ms sql retrieve those fields as BLOB and doesn’t let to sort them.

Any way appreciates.

Dear Otis, I was wondering to ask you a question, if you don’t mind.

Don’t think such a good O/R mapper needs a better document? I think at this time, it has a document, I don’t talk about technical reference, but it a poor document, I should be much better. For first time, when I have tried to read the document, belive me took 3 days and I didn’t get it what’s going on? May be because of me, I don’t know.

By the way, you guys if provide a richer document; I’m sure all software users and developers would appreciate.

Regards,

Shah

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39612
Joined: 17-Aug-2003
# Posted on: 26-Oct-2005 14:57:42   

Shah wrote:

I got it. Actually, I talked to UI guys and I said it doesn’t make sense to have a sort on Text field, because ms sql retrieve those fields as BLOB and doesn’t let to sort them.

exactly.

Dear Otis, I was wondering to ask you a question, if you don’t mind.

Don’t think such a good O/R mapper needs a better document? I think at this time, it has a document, I don’t talk about technical reference, but it a poor document, I should be much better. For first time, when I have tried to read the document, belive me took 3 days and I didn’t get it what’s going on? May be because of me, I don’t know.

By the way, you guys if provide a richer document; I’m sure all software users and developers would appreciate.

Why is it a poor document? It's 334 printed pages, so there's a lot of things explained in there. First the concepts are explained, so things refered to later on are clear, then the designer is discussed so people can familiar themselves with teh gui, then the generated code is discussed, how to do things, building on top of the concepts and the designer docs.

'poor' is too vague, what should change according to you? ("Everything" is a likely answer wink but I hope you understand the scope of LLBLGen Pro is very big and therefore a lot of things have to be explained and the amount of information is massive. Still if you could give me insight what is wrong in the docs and how to change it, we could work on that in the future.)

Frans Bouma | Lead developer LLBLGen Pro
Shah
User
Posts: 6
Joined: 20-Oct-2005
# Posted on: 26-Oct-2005 20:10:53   

Hey Otis, you right. I understand the scope of LLBL Gen.

Do you remember couple days ago I had a question about "how can I add multiple fields to a filter"

I've read the document two or three times, but I couldn't find my answer. Ofcourse I don't expect to find all my answers.

Any way, I think forum is a good place to submit questions and get answers of you as a technical person.

I appriciate of your help.

regards,

Shah

HcD avatar
HcD
User
Posts: 214
Joined: 12-May-2005
# Posted on: 26-Oct-2005 22:51:29   

'poor' is too vague, what should change according to you?

A MUCH bigger "Best practises - How do I ... ?" section smile i find myself always referring to that one first whenever i have a question ;-)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39612
Joined: 17-Aug-2003
# Posted on: 27-Oct-2005 14:28:45   

Shah wrote:

Hey Otis, you right. I understand the scope of LLBL Gen.

Do you remember couple days ago I had a question about "how can I add multiple fields to a filter"

I've read the document two or three times, but I couldn't find my answer. Ofcourse I don't expect to find all my answers.

Though it was there in the manual. BUT I fully admit it's perhaps hard to find. The problem we have is that the more functionality you provide, the more documentation it requires and that will confuse the reader of the documentation, because should he read all of it before starting or not? If it's too much, a user might think "too complex" and will move away from it.

Any way, I think forum is a good place to submit questions and get answers of you as a technical person.

True. Our manual is targeted towards teaching concepts first and examples later. Sometimes people want to work the other way around: learn by example. Then our manual is a bit odd perhaps. Though I'd like to ask you to learn the concepts behind our functionality. If THOSE are unclear, let me know. Once you grasp the concepts, it's pretty straight forward, but if the concepts are documented wrong, it's a tough learning experience.

HcD wrote:

'poor' is too vague, what should change according to you?

A MUCH bigger "Best practises - How do I ... ?" section smile i find myself always referring to that one first whenever i have a question ;-)

simple_smile This was on the list of things to do for 1.0.2005.1. However I was simply out of ideas what to put in there. I'll try to port more unittests to how-do-I questions to see if that helps.

Frans Bouma | Lead developer LLBLGen Pro