How to make Multiple word search in SOLRJQuery - mongodb

I am currently working with SolrJ API for our webapplication. We need to have multiple word search in the application. But I do not know how to do it.
Here is the code we have developed so far by searching on the web.
HttpSolrClient solr = new HttpSolrClient("http://localhost:8983/solr/Test");
SolrQuery query = new SolrQuery();
query.setQuery("product_name:Dell laptop*");
query.setFields("product_name");
query.setStart(0);
query.setRows(1000);
QueryResponse response = solr.query(query);
SolrDocumentList results = response.getResults();
for (int i = 0; i < results.size(); ++i) {
System.out.println(results.get(i));
}
But I am not getting any result output. Our Solr has a mongo DB merged into it with the help of admin console of apache Solr which is running at 8983 port.
Please help. I am new to apache SOLR.
Update :
Here is the schema.xml we have created
<?xml version="1.0" encoding="UTF-8" ?>
<schema name="example" version="1.5">
<field name="_version_" type="long" indexed="true" stored="true"/>
<field name="_root_" type="string" indexed="true" stored="false"/>
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="product_name" type="string" indexed="true" stored="true" required="true" multiValued="true"/>
<field name="product_url" type="string" indexed="true" stored="true" required="true" multiValued="true"/>
<field name="product_img" type="string" indexed="true" stored="true" required="true" multiValued="true"/>
<field name="product_price" type="double" indexed="true" stored="true" required="true" multiValued="true"/>
<dynamicField name="*_i" type="int" indexed="true" stored="true"/>
<dynamicField name="*_is" type="int" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*_s" type="string" indexed="true" stored="true" />
<dynamicField name="*_ss" type="string" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*_l" type="long" indexed="true" stored="true"/>
<dynamicField name="*_ls" type="long" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*_t" type="text_general" indexed="true" stored="true"/>
<dynamicField name="*_txt" type="text_general" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*_en" type="text_en" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*_b" type="boolean" indexed="true" stored="true"/>
<dynamicField name="*_bs" type="boolean" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*_f" type="float" indexed="true" stored="true"/>
<dynamicField name="*_fs" type="float" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*_d" type="double" indexed="true" stored="true"/>
<dynamicField name="*_ds" type="double" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*_coordinate" type="tdouble" indexed="true" stored="false" />
<dynamicField name="*_dt" type="date" indexed="true" stored="true"/>
<dynamicField name="*_dts" type="date" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*_p" type="location" indexed="true" stored="true"/>
<dynamicField name="*_ti" type="tint" indexed="true" stored="true"/>
<dynamicField name="*_tl" type="tlong" indexed="true" stored="true"/>
<dynamicField name="*_tf" type="tfloat" indexed="true" stored="true"/>
<dynamicField name="*_td" type="tdouble" indexed="true" stored="true"/>
<dynamicField name="*_tdt" type="tdate" indexed="true" stored="true"/>
<dynamicField name="*_c" type="currency" indexed="true" stored="true"/>
<dynamicField name="ignored_*" type="ignored" multiValued="true"/>
<dynamicField name="attr_*" type="text_general" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="random_*" type="random" />
<uniqueKey>id</uniqueKey>
<fieldType name="string" class="solr.StrField" sortMissingLast="true" />
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="tint" class="solr.TrieIntField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0"/>
<fieldType name="binary" class="solr.BinaryField"/>
<fieldType name="random" class="solr.RandomSortField" indexed="true" />
<fieldType name="text_ws" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
</analyzer>
</fieldType>
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
<fieldType name="text_en" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory"
ignoreCase="true"
words="lang/stopwords_en.txt"
/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EnglishPossessiveFilterFactory"/>
<filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
<filter class="solr.PorterStemFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.StopFilterFactory"
ignoreCase="true"
words="lang/stopwords_en.txt"
/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EnglishPossessiveFilterFactory"/>
<filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
<filter class="solr.PorterStemFilterFactory"/>
</analyzer>
</fieldType>
<fieldType name="text_en_splitting" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.StopFilterFactory"
ignoreCase="true"
words="lang/stopwords_en.txt"
/>
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
<filter class="solr.PorterStemFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.StopFilterFactory"
ignoreCase="true"
words="lang/stopwords_en.txt"
/>
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
<filter class="solr.PorterStemFilterFactory"/>
</analyzer>
</fieldType>
<fieldType name="text_en_splitting_tight" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">
<analyzer>
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="false"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_en.txt"/>
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="0" generateNumberParts="0" catenateWords="1" catenateNumbers="1" catenateAll="0"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
<filter class="solr.EnglishMinimalStemFilterFactory"/>
<filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
</analyzer>
</fieldType>
<fieldType name="text_general_rev" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ReversedWildcardFilterFactory" withOriginal="true"
maxPosAsterisk="3" maxPosQuestion="2" maxFractionAsterisk="0.33"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
<fieldType name="alphaOnlySort" class="solr.TextField" sortMissingLast="true" omitNorms="true">
<analyzer>
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory" />
<filter class="solr.TrimFilterFactory" />
<filter class="solr.PatternReplaceFilterFactory"
pattern="([^a-z])" replacement="" replace="all"
/>
</analyzer>
</fieldType>
<fieldType name="lowercase" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
<fieldType name="ignored" stored="false" indexed="false" multiValued="true" class="solr.StrField" />
<fieldType name="point" class="solr.PointType" dimension="2" subFieldSuffix="_d"/>
<fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
<fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType"
geo="true" distErrPct="0.025" maxDistErr="0.001" distanceUnits="kilometers" />
<fieldType name="bbox" class="solr.BBoxField"
geo="true" distanceUnits="kilometers" numberType="_bbox_coord" />
<fieldType name="_bbox_coord" class="solr.TrieDoubleField" precisionStep="8" docValues="true" stored="false"/>
<fieldType name="currency" class="solr.CurrencyField" precisionStep="8" defaultCurrency="USD" currencyConfig="currency.xml" />
</schema>
And here is the data-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource name="client_XXXX" type="MongoDataSource" database="client_XXXX" host="192.168.11.XXX" port="27017"/>
<document name="Titles">
<entity name="TitleEntity"
processor="MongoEntityProcessor"
query=""
collection="XXXX_data"
datasource="client_XXXX"
transformer="MongoMapperTransformer" >
<field column="product_name" name="product_name"/>
<field column="product_url" name="product_url"/>
<field column="product_img" name="product_img"/>
<field column="product_price" name="product_price"/>
<field column="_id" name="id"/>
</entity>
</document>
</dataConfig>

What you are running into is mentioned in Lucene's JavaDoc. Why Lucene? Solr's query syntax is a superset of Lucene's. As mentioned there
Note: The field is only valid for the term that it directly precedes, so the query
title:Do it right
Will only find "Do" in the title field. It will find "it" and "right" in the default field (in this case the text field).
In your case only Dell is directed to the field product_name, the rest is directed to the default search field defined in your configuration.
What you want to use to get around this is called Field Grouping. Therefore you need to surround the words that shall go to one field with round brackets, like this
SolrQuery query = new SolrQuery();
query.setQuery("product_name:(Dell laptop*)"); // surround the words with ( ... )
query.setFields("product_name");
query.setStart(0);
query.setRows(1000);

We created a new schema.xml by removing unwanted references here is the schema we used.
<schema name="example" version="1.5">
<field name="_version_" type="long" indexed="true" stored="true"/>
<field name="_root_" type="string" indexed="true" stored="false"/>
<fields>
<field name="id" type="long" indexed="true" stored="true" required="true" multiValued="false" />
<field name="product_name" type="string" indexed="true" stored="true" required="true" />
<field name="product_price" type="" indexed="true" stored="true" required="true" />
</fields>
<uniqueKey>id</uniqueKey>
<types>
<fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" omitNorms="true" positionIncrementGap="0" />
<fieldType name="text_wslc" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
<fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
<fieldType name="tdate" class="solr.TrieDateField" omitNorms="true" precisionStep="6" positionIncrementGap="0"/>
<fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>
</types>
<defaultSearchField>product_name</defaultSearchField>
<!-- we don't want too many results in this usecase -->
<solrQueryParser defaultOperator="AND"/>
</schema>

Related

Adding custom properties in workflow task at "workflow I have started " page alfresco share

I need to add custom properties in task row at the "workflow I have started" page.By default one task bar/row contains properties such as due,description,type and started.How to customize to add our custom properties along/instead of these properties.
You can define new form in form configuration with id as workflow-details.Check share-workflow-form-config.xml for more details.Given below is the example of one form taken from the same file, which is defining properties of the page you mentioned.
<config evaluator="task-type" condition="bpm:startTask">
<forms>
<form id="workflow-details">
<field-visibility>
<show id="bpm:sendEMailNotifications" />
<show id="packageItems" />
</field-visibility>
<appearance>
<set id="" appearance="title" label-id="workflow.set.workflow.more_info" />
<set id="items" appearance="title" label-id="workflow.set.items" />
<field id="packageItems" set="items" />
</appearance>
</form>
<form>
<field-visibility>
<show id="message" />
<show id="taskOwner" />
<show id="bpm:workflowPriority" />
<show id="bpm:workflowDueDate" />
<show id="bpm:taskId" />
<show id="bpm:status" />
<show id="packageItems" />
<show id="bpm:sendEMailNotifications" />
</field-visibility>
<appearance>
<set id="" appearance="title" label-id="workflow.set.task.info" />
<set id="info" appearance="" template="/org/alfresco/components/form/3-column-set.ftl" />
<set id="progress" appearance="title" label-id="workflow.set.task.progress" />
<set id="items" appearance="title" label-id="workflow.set.items" />
<set id="other" appearance="title" label-id="workflow.set.other" />
<field id="message">
<control template="/org/alfresco/components/form/controls/info.ftl" />
</field>
<field id="taskOwner" set="info" />
<field id="bpm:taskId" set="info">
<control template="/org/alfresco/components/form/controls/info.ftl" />
</field>
<field id="bpm:workflowPriority" label-id="workflow.field.priority" set="info" read-only="true">
<control template="/org/alfresco/components/form/controls/workflow/priority.ftl" />
</field>
<field id="bpm:workflowDueDate" set="info" label-id="workflow.field.due">
<control template="/org/alfresco/components/form/controls/info.ftl" />
</field>
<field id="bpm:status" set="progress" />
<field id="bpm:sendEMailNotifications" set="other" />
<field id="packageItems" set="items" />
</appearance>
</form>
</forms>

Solr DataImportHandler can't add/update with postgresql

I am trying to index the postgresql table in solr using DataImportHandler, but it's seems not indexing
Dataimport result :
{
"responseHeader": {
"status": 0,
"QTime": 45
},
"initArgs": [
"defaults",
[
"config",
"db-data-config.xml"
]
],
"command": "full-import",
"mode": "debug",
"documents": [],
"verbose-output": [],
"status": "idle",
"importResponse": "",
"statusMessages": {
"Total Requests made to DataSource": "1",
"Total Rows Fetched": "10",
"Total Documents Skipped": "0",
"Full Dump Started": "2015-02-15 20:54:55",
"": "Indexing completed. Added/Updated: 0 documents. Deleted 0 documents.",
"Committed": "2015-02-15 20:54:55",
"Total Documents Processed": "0",
"Time taken": "0:0:0.37"
},
"WARNING": "This response format is experimental. It is likely to change in the future."
}
db-data-config.xml :
<document>
<entity name="baby" query="SELECT NAME_ID, BORN_YEAR, FISRT_NAME, BORN_COUNTRY, BABY_SEX, NAME_COUNT from SAMPLE_BABY_NAMES">
<field column="NAME_ID" name="id"/>
<field column="FISRT_NAME" name="name"/>
<field column="BORN_YEAR" name="born"/>
<field column="BORN_COUNTRY" name="country"/>
<field column="BABY_SEX" name="sex"/>
<field column="NAME_COUNT" name="count"/>
</entity>
</document>
schema.xml filds :
<fields>
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false"/>
<field name="sku" type="textTight" indexed="true" stored="true" omitNorms="true"/>
<field name="name" type="text" indexed="true" stored="true"/>
<field name="nameSort" type="string" indexed="true" stored="false"/>
<field name="alphaNameSort" type="alphaOnlySort" indexed="true" stored="false"/>
<field name="manu" type="text" indexed="true" stored="true" omitNorms="true"/>
<field name="cat" type="text_ws" indexed="true" stored="true" multiValued="true" omitNorms="true" termVectors="true"/>
<field name="features" type="text" indexed="true" stored="true" multiValued="true"/>
<field name="includes" type="text" indexed="true" stored="true"/>
<field name="weight" type="sfloat" indexed="true" stored="true"/>
<field name="price" type="sfloat" indexed="true" stored="true"/>
<field name="popularity" type="sint" indexed="true" stored="true" default="0"/>
<field name="inStock" type="boolean" indexed="true" stored="true"/>
<field name="word" type="string" indexed="true" stored="true"/>
<field name="text" type="text" indexed="true" stored="false" multiValued="true"/>
<field name="manu_exact" type="string" indexed="true" stored="false"/>
<field name="_version_" type="long" indexed="true" stored="true"/>
<field name="born" type="text" indexed="true" stored="true"/>
<field name="country" type="text" indexed="true" stored="true"/>
<field name="sex" type="text" indexed="true" stored="true"/>
<field name="count" type="text" indexed="true" stored="true"/>
<dynamicField name="*_i" type="sint" indexed="true" stored="true"/>
<dynamicField name="*_s" type="string" indexed="true" stored="true"/>
<dynamicField name="*_l" type="slong" indexed="true" stored="true"/>
<dynamicField name="*_t" type="text" indexed="true" stored="true"/>
<dynamicField name="*_b" type="boolean" indexed="true" stored="true"/>
<dynamicField name="*_f" type="sfloat" indexed="true" stored="true"/>
<dynamicField name="*_d" type="sdouble" indexed="true" stored="true"/>
<dynamicField name="*_dt" type="date" indexed="true" stored="true"/>
<dynamicField name="random*" type="random"/>
</fields>
I am using solr4.5.0 with tomcat7 and postgresql 9.4

QuickFIX/n and FXALL

I am trying to send a MarketDataRequest to FXAll FIX Server using FIX 4.3 standard. Looking at the documentation the response from the server should be as follow
<message name="MarketDataIncrementalRefresh" msgtype="X" msgcat="app">
<field name="MDReqID" required="N" />
<group name="NoMDEntries" required="Y">
<field name="MDUpdateAction" required="Y" />
<field name="DeleteReason" required="N" />
<field name="MDEntryType" required="N" />
<field name="MDEntryID" required="N" />
<field name="MDEntryRefID" required="N" />
<component name="Instrument" required="N" />
<field name="FinancialStatus" required="N" />
<field name="CorporateAction" required="N" />
... omissis ...
</group>
</message>
but in the FXAll API Documentation field 55 (Instrument o Symbol) is expected just after the field MDReqID like it should be on the standard MarketDataSnapshotFullRefresh message
<message name="MarketDataSnapshotFullRefresh" msgtype="W" msgcat="app">
<field name="MDReqID" required="N" />
<component name="Instrument" required="Y" />
... omissis ...
</message>
Of course QuickFix/n engine is trapping a message MarketDataIncrementalRefresh with the field msgtype="X" and then I always have a TagNotDefinedForMessage error. How to solve this problem?
Thank in advance.
We modified our FIX43.xml file to FIX43_FXALL.xml and specific in the quickfix config file that we wanted to use that specific data dictionary (ie we used the direct path the file).
The modification looked like this:
<message name="MarketDataIncrementalRefresh" msgtype="X" msgcat="app">
<field name="MDReqID" required="N" />
<component name="Instrument" required="Y" />
<group name="NoMDEntries" required="Y">
<field name="MDUpdateAction" required="Y" />
<field name="MDEntryType" required="Y" />
<field name="MDEntryID" required="Y" />
<field name="MDEntryRefID" required="N" />
<field name="MDEntryPx" required="N" />
<field name="MDEntrySize" required="N" />
<field name="QuoteType" required="N" />
<field name="MDEntryOriginator" required="N" />
<field name="MinQty" required="N" />
<field name="MDEntryPositionNo" required="N" />
<field name="MDEntryDate" required="N" />
<field name="MDEntryTime" required="N" />
<field name="TickDirection" required="N" />
<field name="MDMkt" required="N" />
<field name="TradingSessionID" required="N" />
<field name="TradingSessionSubID" required="N" />
<field name="QuoteCondition" required="N" />
<field name="TradeCondition" required="N" />
<field name="MDEntryOriginator" required="N" />
<field name="LocationID" required="N" />
<field name="DeskID" required="N" />
<field name="OpenCloseSettleFlag" required="N" />
<field name="TimeInForce" required="N" />
<field name="ExpireDate" required="N" />
<field name="ExpireTime" required="N" />
<field name="ExecInst" required="N" />
<field name="SellerDays" required="N" />
<field name="OrderID" required="N" />
<field name="QuoteEntryID" required="N" />
<field name="MDEntryBuyer" required="N" />
<field name="MDEntrySeller" required="N" />
<field name="NumberOfOrders" required="N" />
<field name="Scope" required="N" />
<field name="TotalVolumeTraded" required="N" />
<field name="TotalVolumeTradedDate" required="N" />
<field name="TotalVolumeTradedTime" required="N" />
<field name="NetChgPrevDay" required="N" />
<field name="Text" required="N" />
<field name="EncodedTextLen" required="N" />
<field name="EncodedText" required="N" />
</group>
<field name="FutSettDate" required="Y" />
</message>

entity framework - inheritance design

Using .Net 4 with EF 1.0: I have a table per type inheritance database structure and edmx (see diagram and cutdown edmx at the end of the post. The edmx is created through a code generator). I've just included one subtype for this post but there are many!
All of our entity framework queries are also dynamically generated. So at the moment when I try to retrieve a product (which may or may not be a book) I have the following ESQL query being generated.
SELECT VALUE [tb_product] FROM [tb_product] as [tb_product] WHERE (([tb_product].[Id] = #p0))
If the object I've requested is a book, the object I'm getting returned to me is of type 'tb_product'. I can't seem to cast or otherwise access the 'book' information from this tb_product object.
How can I modify the query, edmx or some other component so that when I query the base type I can also access all relevant subtype information without a second database trip. Can I?
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="MyModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2005" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">
<EntityContainer Name="MyModelStoreContainer">
<EntitySet Name="tb_productBook" EntityType="MyModel.Store.tb_productBook" store:Type="Tables" Schema="dbo" />
<EntitySet Name="tb_product" EntityType="MyModel.Store.tb_product" store:Type="Tables" Schema="dbo" />
<AssociationSet Name="FK_IdProductBook_Product" Association="MyModel.Store.FK_IdProductBook_Product">
<End Role="tb_product" EntitySet="tb_product" />
<End Role="tb_productBook" EntitySet="tb_productBook" />
</AssociationSet>
</EntityContainer>
<EntityType Name="tb_productBook">
<Key>
<PropertyRef Name="id" />
</Key>
<Property Name="id" Type="int" Nullable="false" />
<Property Name="title" Type="varchar" Nullable="false" MaxLength="150" />
<Property Name="subtitle" Type="varchar" Nullable="false" MaxLength="150" />
<Property Name="length" Type="int" Nullable="false" />
<Property Name="productCoverTypeId" Type="int" Nullable="false" />
<Property Name="volumeEdition" Type="varchar" Nullable="false" MaxLength="15" />
<Property Name="publisherName" Type="varchar" Nullable="false" MaxLength="100" />
<Property Name="publishDate" Type="datetime" />
<Property Name="iSBNNumber" Type="varchar" Nullable="false" MaxLength="30" />
<Property Name="description" Type="varchar" Nullable="false" />
<Property Name="authorBio" Type="varchar" Nullable="false" />
<Property Name="audience" Type="varchar" Nullable="false" />
<Property Name="expireDate" Type="datetime" />
<Property Name="vendorId" Type="int" Nullable="false" />
<Property Name="productCommissionTypeId" Type="int" Nullable="false" />
<Property Name="commissionValue" Type="decimal" Nullable="false" Precision="9" Scale="2" />
<Property Name="languageId" Type="int" Nullable="false" />
<Property Name="countryId" Type="int" Nullable="false" />
<Property Name="stateId" Type="int" Nullable="false" />
<Property Name="inventoryLocation" Type="varchar" Nullable="false" MaxLength="2000" />
</EntityType>
<EntityType Name="tb_product">
<Key>
<PropertyRef Name="id" />
</Key>
<Property Name="id" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
<Property Name="name" Type="varchar" MaxLength="100" />
<Property Name="productSku" Type="varchar" Nullable="false" MaxLength="17" />
<Property Name="productTypeId" Type="int" Nullable="false" />
<Property Name="price" Type="decimal" Nullable="false" Precision="9" Scale="2" />
<Property Name="marketOnWeb" Type="bit" Nullable="false" />
<Property Name="subsidiaryId" Type="int" Nullable="false" />
<Property Name="lmsProductId" Type="int" />
<Property Name="topicId" Type="int" />
<Property Name="categoryId" Type="int" />
<Property Name="eventId" Type="int" />
<Property Name="note" Type="varchar" />
<Property Name="expirationDate" Type="datetime" />
<Property Name="mediaLength" Type="int" />
<Property Name="urlSlug" Type="varchar" MaxLength="200" />
<Property Name="productSourceId" Type="int" />
<Property Name="created" Type="datetime" Nullable="false" />
<Property Name="createdBy" Type="varchar" Nullable="false" MaxLength="30" />
<Property Name="lastUpdated" Type="datetime" Nullable="false" />
<Property Name="lastUpdatedBy" Type="varchar" Nullable="false" MaxLength="30" />
</EntityType>
<Association Name="FK_IdProductBook_Product">
<End Role="tb_product" Type="MyModel.Store.tb_product" Multiplicity="1">
<OnDelete Action="Cascade" />
</End>
<End Role="tb_productBook" Type="MyModel.Store.tb_productBook" Multiplicity="0..1" />
<ReferentialConstraint>
<Principal Role="tb_product">
<PropertyRef Name="id" />
</Principal>
<Dependent Role="tb_productBook">
<PropertyRef Name="id" />
</Dependent>
</ReferentialConstraint>
</Association>
</Schema>
</edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
<Schema Namespace="MyModel" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm">
<EntityContainer Name="MyEntities">
<EntitySet Name="tb_product" EntityType="MyModel.tb_product" />
</EntityContainer>
<EntityType Name="tb_productBook" BaseType="MyModel.tb_product">
<Property Name="title" Type="String" Nullable="false" />
<Property Name="subtitle" Type="String" Nullable="false" />
<Property Name="length" Type="Int32" Nullable="false" />
<Property Name="volumeEdition" Type="String" Nullable="false" />
<Property Name="publisherName" Type="String" Nullable="false" />
<Property Name="publishDate" Type="DateTime" Nullable="true" />
<Property Name="iSBNNumber" Type="String" Nullable="false" />
<Property Name="description" Type="String" Nullable="false" />
<Property Name="authorBio" Type="String" Nullable="false" />
<Property Name="audience" Type="String" Nullable="false" />
<Property Name="expireDate" Type="DateTime" Nullable="true" />
<Property Name="vendorId" Type="Int32" Nullable="false" />
<Property Name="commissionValue" Type="Decimal" Nullable="false" />
<Property Name="inventoryLocation" Type="String" Nullable="false" />
<NavigationProperty Name="ProductBook_Country" Relationship="MyModel.FK_CountryProductBook_Country" FromRole="tb_productBook" ToRole="tb_country" />
<NavigationProperty Name="ProductBook_Language" Relationship="MyModel.FK_LanguageProductBook_Language" FromRole="tb_productBook" ToRole="tb_language" />
<NavigationProperty Name="ProductBook_ProductCommissionType" Relationship="MyModel.FK_ProductCommissionTypeProductBook_ProductCommissionType" FromRole="tb_productBook" ToRole="tb_productCommissionType" />
<NavigationProperty Name="ProductBook_ProductCoverType" Relationship="MyModel.FK_ProductCoverTypeProductBook_ProductCoverType" FromRole="tb_productBook" ToRole="tb_productCoverType" />
<NavigationProperty Name="ProductBook_State" Relationship="MyModel.FK_StateProductBook_State" FromRole="tb_productBook" ToRole="tb_state" />
</EntityType>
<EntityType Name="tb_product">
<Key>
<PropertyRef Name="id" />
</Key>
<Property Name="id" Type="Int32" Nullable="false" />
<Property Name="name" Type="String" Nullable="true" />
<Property Name="productSku" Type="String" Nullable="false" />
<Property Name="price" Type="Decimal" Nullable="false" />
<Property Name="marketOnWeb" Type="Boolean" Nullable="false" />
<Property Name="subsidiaryId" Type="Int32" Nullable="false" />
<Property Name="lmsProductId" Type="Int32" Nullable="true" />
<Property Name="topicId" Type="Int32" Nullable="true" />
<Property Name="note" Type="String" Nullable="true" />
<Property Name="expirationDate" Type="DateTime" Nullable="true" />
<Property Name="mediaLength" Type="Int32" Nullable="true" />
<Property Name="urlSlug" Type="String" Nullable="true" />
<Property Name="created" Type="DateTime" Nullable="false" />
<Property Name="createdBy" Type="String" Nullable="false" />
<Property Name="lastUpdated" Type="DateTime" Nullable="false" />
<Property Name="lastUpdatedBy" Type="String" Nullable="false" />
<NavigationProperty Name="CampaignAdvertisedProduct_Product" Relationship="MyModel.FK_ProductCampaignAdvertisedProduct_Product" FromRole="tb_product" ToRole="tb_campaignAdvertisedProduct" />
<NavigationProperty Name="DiscountGroupProduct_Product" Relationship="MyModel.FK_ProductDiscountGroupProduct_Product" FromRole="tb_product" ToRole="tb_discountGroupProduct" />
<NavigationProperty Name="LogCampaignResponseUpdate_Product" Relationship="MyModel.FK_ProductLogCampaignResponseUpdate_Product" FromRole="tb_product" ToRole="tb_logCampaignResponseUpdate" />
<NavigationProperty Name="ProductAuthor_Product" Relationship="MyModel.FK_ProductProductAuthor_Product" FromRole="tb_product" ToRole="tb_productAuthor" />
<NavigationProperty Name="ProductImage_Product" Relationship="MyModel.FK_ProductProductImage_Product" FromRole="tb_product" ToRole="tb_productImage" />
<NavigationProperty Name="ProductMarketingContent_Product" Relationship="MyModel.FK_ProductProductMarketingContent_Product" FromRole="tb_product" ToRole="tb_productMarketingContent" />
<NavigationProperty Name="ProductOnsiteStaffAgency_Product" Relationship="MyModel.FK_ProductProductOnsiteStaffAgency_Product" FromRole="tb_product" ToRole="tb_productOnsiteStaffAgency" />
<NavigationProperty Name="ProductProblem_Product" Relationship="MyModel.FK_ProductProductProblem_Product" FromRole="tb_product" ToRole="tb_productProblem" />
<NavigationProperty Name="ProductVenue_Product" Relationship="MyModel.FK_ProductProductVenue_Product" FromRole="tb_product" ToRole="tb_productVenue" />
<NavigationProperty Name="VenueEmailRequest_Product" Relationship="MyModel.FK_ProductVenueEmailRequest_Product" FromRole="tb_product" ToRole="tb_venueEmailRequest" />
<NavigationProperty Name="Product_Category" Relationship="MyModel.FK_CategoryProduct_Category" FromRole="tb_product" ToRole="tb_category" />
<NavigationProperty Name="Product_ProductSource" Relationship="MyModel.FK_ProductSourceProduct_ProductSource" FromRole="tb_product" ToRole="tb_productSource" />
<NavigationProperty Name="Product_ProductType" Relationship="MyModel.FK_ProductTypeProduct_ProductType" FromRole="tb_product" ToRole="tb_productType" />
<NavigationProperty Name="Product_Event" Relationship="MyModel.FK_EventProduct_Event" FromRole="tb_product" ToRole="tb_event" />
<NavigationProperty Name="tb_category" Relationship="MyModel.tb_product_category" FromRole="tb_product" ToRole="tb_category" />
<NavigationProperty Name="tb_contact" Relationship="MyModel.tb_product_faculty" FromRole="tb_product" ToRole="tb_contact" />
<NavigationProperty Name="tb_state" Relationship="MyModel.tb_product_State" FromRole="tb_product" ToRole="tb_state" />
<NavigationProperty Name="tb_vendorCost" Relationship="MyModel.tb_product_VendorCost" FromRole="tb_product" ToRole="tb_vendorCost" />
<NavigationProperty Name="tb_vendorInvoice" Relationship="MyModel.tb_product_VendorInvoice" FromRole="tb_product" ToRole="tb_vendorInvoice" />
<NavigationProperty Name="tb_vendorPayment" Relationship="MyModel.tb_product_VendorPayment" FromRole="tb_product" ToRole="tb_vendorPayment" />
</EntityType>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">
<EntityContainerMapping StorageEntityContainer="MyModelStoreContainer" CdmEntityContainer="MyEntities">
<EntitySetMapping Name="tb_product">
<EntityTypeMapping TypeName="IsTypeOf(MyModel.tb_product)">
<MappingFragment StoreEntitySet="tb_product">
<ScalarProperty Name="lastUpdatedBy" ColumnName="lastUpdatedBy" />
<ScalarProperty Name="lastUpdated" ColumnName="lastUpdated" />
<ScalarProperty Name="createdBy" ColumnName="createdBy" />
<ScalarProperty Name="created" ColumnName="created" />
<ScalarProperty Name="urlSlug" ColumnName="urlSlug" />
<ScalarProperty Name="mediaLength" ColumnName="mediaLength" />
<ScalarProperty Name="expirationDate" ColumnName="expirationDate" />
<ScalarProperty Name="note" ColumnName="note" />
<ScalarProperty Name="topicId" ColumnName="topicId" />
<ScalarProperty Name="lmsProductId" ColumnName="lmsProductId" />
<ScalarProperty Name="subsidiaryId" ColumnName="subsidiaryId" />
<ScalarProperty Name="marketOnWeb" ColumnName="marketOnWeb" />
<ScalarProperty Name="price" ColumnName="price" />
<ScalarProperty Name="productSku" ColumnName="productSku" />
<ScalarProperty Name="name" ColumnName="name" />
<ScalarProperty Name="id" ColumnName="id" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(MyModel.tb_productBook)">
<MappingFragment StoreEntitySet="tb_productBook">
<ScalarProperty Name="inventoryLocation" ColumnName="inventoryLocation" />
<ScalarProperty Name="commissionValue" ColumnName="commissionValue" />
<ScalarProperty Name="vendorId" ColumnName="vendorId" />
<ScalarProperty Name="expireDate" ColumnName="expireDate" />
<ScalarProperty Name="audience" ColumnName="audience" />
<ScalarProperty Name="authorBio" ColumnName="authorBio" />
<ScalarProperty Name="description" ColumnName="description" />
<ScalarProperty Name="iSBNNumber" ColumnName="iSBNNumber" />
<ScalarProperty Name="publishDate" ColumnName="publishDate" />
<ScalarProperty Name="publisherName" ColumnName="publisherName" />
<ScalarProperty Name="volumeEdition" ColumnName="volumeEdition" />
<ScalarProperty Name="length" ColumnName="length" />
<ScalarProperty Name="subtitle" ColumnName="subtitle" />
<ScalarProperty Name="title" ColumnName="title" />
<ScalarProperty Name="id" ColumnName="id" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
</EntityContainerMapping>
</Mapping>
</edmx:Mappings>

Firebird .NET Provider 2.7.5: Value cannot be null. Parameter name: key

This worked with Firebird .NET Provider 2.6.5:
using (var context = new SetupContext())
{
_maxApplicationID = context.Application.Max(a => (int?)a.ID) ?? 0;
}
Table Mapping:
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="Model1.Store" Alias="Self" Provider="FirebirdSql.Data.FirebirdClient" ProviderManifestToken="2.5" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
<EntityContainer Name="Model1StoreContainer">
<EntitySet Name="APPLICATION" EntityType="Model1.Store.APPLICATION" store:Type="Tables" Schema="Firebird" />
</EntityContainer>
<EntityType Name="APPLICATION">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="int" Nullable="false" />
<Property Name="NAME" Type="varchar" Nullable="false" MaxLength="50" />
<Property Name="DISPLAY_TEXT" Type="varchar" MaxLength="255" />
<Property Name="ARGUMENTS" Type="varchar" MaxLength="255" />
<Property Name="PATH" Type="varchar" MaxLength="255" />
<Property Name="TYPE" Type="char" MaxLength="1" />
</EntityType>
</Schema>
</edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
<Schema Namespace="Model1" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityContainer Name="Entities" annotation:LazyLoadingEnabled="true">
<EntitySet Name="Application" EntityType="Model1.Application" />
</EntityContainer>
<EntityType Name="Application">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="Int32" Nullable="false" />
<Property Name="Name" Type="String" Nullable="false" MaxLength="50" Unicode="true" FixedLength="false" />
<Property Name="DisplayText" Type="String" MaxLength="255" Unicode="true" FixedLength="false" />
<Property Name="Arguments" Type="String" MaxLength="255" Unicode="true" FixedLength="false" />
<Property Name="Path" Type="String" MaxLength="255" Unicode="true" FixedLength="false" />
<Property Name="Type" Type="String" MaxLength="1" Unicode="true" FixedLength="true" />
</EntityType>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs">
<EntityContainerMapping StorageEntityContainer="Model1StoreContainer" CdmEntityContainer="Entities">
<EntitySetMapping Name="Application"><EntityTypeMapping TypeName="Model1.Application"><MappingFragment StoreEntitySet="APPLICATION">
<ScalarProperty Name="ID" ColumnName="ID" />
<ScalarProperty Name="Name" ColumnName="NAME" />
<ScalarProperty Name="DisplayText" ColumnName="DISPLAY_TEXT" />
<ScalarProperty Name="Arguments" ColumnName="ARGUMENTS" />
<ScalarProperty Name="Path" ColumnName="PATH" />
<ScalarProperty Name="Type" ColumnName="TYPE" />
</MappingFragment></EntityTypeMapping></EntitySetMapping>
</EntityContainerMapping>
</Mapping>
</edmx:Mappings>
Now I have upgraded to version Firebird .NET Provider 2.7.5 and I'm getting an ArgumentNullException saying that "Value cannot be null. Parameter name: key".
Is this a changed behaviour in 2.7.5 or did somthing went wrong with the update. If this is a changed behaviour: How can I get the maximum value of a column?
If done as Mark Rotteveel suggested. This is the link to the ticket in the firebird bug database: http://tracker.firebirdsql.org/browse/DNET-429