I found LINQtoCRM (http://linqtocrm.codeplex.com/) and I started playing with it. It's nice, but before I get carried away I found there appears to be a showstopper: I can't figure out how to query against DynamicEntities (so I can query against my custom entities). Can someone confirm if this is currently impossible? Or give an example of how one would go about it?
This works:
var res = from c in p.Linq<task>()
select c;
string msg = "";
foreach (task dyn in res.ToList<task>())
{
msg += dyn.ToString();
}
If you s/task/DynamicEntity/ it no longer works :) Just want to confirm it's currently undoable before I go write lots more boilerplate...
edit: angle brackets
(I implemented the original version of LinqtoCRM and I'm still a maintainer).
I do not believe dynamic entities are supported. There is some related discussion on the forum. Maybe give XrmLinq a try.
Related
(It's been a while since I've been here.)
I've been using the first version of PHRets v1 for years, and understood it well enough to get by, but now I'm trying to understand the advantages of v2.6.2. I've got it all installed and the basics are working fine. My issues are pretty much with comprehending fine points of query syntax that goes into the rets=>Search() statement. (I'm much more familiar with SQL statements). Specifically, I'd like to have a query return a list of properties, EXCLUDING those which already have the status of "Sold".
Here's where I am stuck: If I start with this
`$results = $rets->Search('Property', 'A','*',['Select' => 'LIST_8,LIST_105,LIST_15,LIST_19,listing_office_shortid']);`
That works well enough. BUT I'd like to fit in a filter like:
"LIST_15 != Sold", or "NOT LIST_15=Sold"...something like that. I don't get how to fit/type that into a PHRets Search().
I like PHRets but it is so hard to find well-organized/complete documentation about specific things like this. Thanks in advance.
As in my comment above I've figured out that the filter goes in the third argument position ('*', as in the original question). The tricky thing was having to find a specific "sold" code for each class of properties and placing it in that position like so: '(LIST_15=~B4ZIT1Y75TZ)', (notice the =~ combination of characters that means "does not equal" in this context). I've found the code strings for each of the property types (not clear WHY they would need to be unique for each type of property: "Sold" is Sold for any type, after all) but the correct code for a single-family residential property (type 'A' ...at least for the MLS in which I have to search is:
$results = $rets->Search('Property', 'A','(LIST_15=~B4ZIT1Y75TZ)',['Select' => 'LIST_8,LIST_105,LIST_15,LIST_19,listing_office_shortid']);
(again, the code to go with LIST_15 will be different for the different types of properties.) I think there is a better answer that involves more naturalistic language, but this works and I guess I will have to be satisfied with it for now. I hope this is of some use to anyone else struggling with this stuff.
First of all, I know title of my question is ambiguous, but I don't know how to say. You'll know when you see my example.
In SQL queries, you can apply dynamic conditions with '1=1'.
Let me give example.
select * from PROD.EMPLY
WHERE 1=1
AND ( NAME = 'JOHN' OR NAME = 'MARY' OR NAME = 'KEVIN') ;
As above, I want to apply filters like below.
BooleanFilter BF = new BooleanFilter();
TermsFilter tf1 = new TermsFilter();
TermsFilter tf2 = new TermsFilter();
//tf1 => 1=1
//tf2 => name condition
tf2.addTerm("name", "JOHN");
tf2.addTerm("name", "MARY");
tf2.addTerm("name", "KEVIN");
BF.add(new FilterClause(tf1, Occur.MUST)); // 1=1 condition
BF.add(new FilterClause(tf2, Occur.MUST)); // name condition
But the results aren't matched as I expected.(no hits)
As I know, it's because there's no null/empty search method in Lucene.
I also checked whether I can switch BooleanFilter/TermsFilter with MatchAllDocsQuery.
However in my case, my Lucene version is so old(2.3.2) that there's no MatchAllDocsQuery in my version, and I don't want filter's conditions to affect to lucene's scoring.
I searched within stackoverflow and google, but there's no case which matches my situation.
Any help would be very appreciated and thanks for reading.
I didn't want to answer myself, but I hope that my poor solution may help/inspire someone who have same trouble.
In my case, as above, my Lucene version is so lower version that many filters are restricted.
However, I didn't want to use query, because I didn't want filters to affect to scoring.
So, I cleared myself by "manual" filter.
My development language was Java, so I used contains method.
To brief my solution, like below.
Search Lucene with AS-IS method.
Within result, compare with contains method (I added this step.)
example :
if (result.contains("KEVIN") ) {
isFilteredResult = true;
} else if (result.contains("JOHN") ) {
isFilteredResult = true;
}
...
The only results which contains condition keywords are displayed.
I was worried about this solution because this way is done with not Lucene but Java step. So, I guessed so much memory would be consumed.
However, the perfomance isn't bad as I was worried, and the users are satisfied with both performance and results.
I know this solution isn't good way, but if the condition is so restricted, this way would also a solution.
Thanks for reading.
And if there's better solution, please let me know.
I asked this question in the Storm user group and haven't gotten a response yet, so I decided to ask it here. I've found the code, and many references to how the the taskIndex is calculated but when I try using the following I don't get the same result as my Storm topology. I've also seen more than one posting where others report the same.
Here's the question:
Hello,
I’ve tried to use the information below to generate the hash, mod it, and in turn, calculate the correct consuming destination task index, but without success. I’ve scoured the Internet to find an example of a hand calculation of this nature and have turned up empty. I must be missing something in my hand calc, so I’m hoping someone on the list can help me out.
I have field grouped as follows:
.fieldsGrouping(EXAMPLE_BOLT, EXAMPLE_BOLT_STREAM, new Fields(TopologyConstants.EXAMPLE_FIELD_GROUPING_ID))
My EXAMPLE_BOLT emits as shown here:
collector.emit(TopologyConstants.EXAMPLE_BOLT_STREAM, new Values(EXAMPLE_FIELD_GROUPING_ID_VALUE, EXAMPLE_DATA_INSTANCE));
I perform the calculation as follows:
int numberOfConsumingTasks = x;
Integer EXAMPLE_FIELD_GROUPING_ID_VALUE = y;
ArrayList alist = new ArrayList();
alist.add(EXAMPLE_FIELD_GROUPING_ID_VALUE);
int hashCode = Arrays.deepHashCode(alist.toArray());
int targetTaskIndex = Math.abs(hashCode) % numberOfConsumingTasks;
The resulting targetTaskIndex value from this calculation does not match the value produced by Storm, when I use real values from my topology.
Can someone tell me what I’m doing wrong?
Thanks,
Aubrey
I've hit a pretty major snag with the entities generated by spmetal / linq to sharepoint. I am hoping someone has dealt with this before.. or maybe I am missing something obvious.
Let's say we have a list with a number field. The field will be expected to hold reasonably precise values.. for example, 0.0000451. Once the value is in the list- SharePoint is fine with it. It displays in the list and display/edit views correctly.
Now if we generate entities based on this list with spmetal, we will get..
//...
private System.Nullable<double> _number;
//..
[Microsoft.SharePoint.Linq.ColumnAttribute(Name="Number", Storage="_number", Required=true, FieldType="Number")]
public System.Nullable<double> Number {
get {
return this._number;
}
set {
if ((value != this._number))
{
this.OnPropertyChanging("Number", this._number);
this._number= value;
this.OnPropertyChanged("Number");
}
}
}
//...
Since the type determined by spmetal is doublewe get notation when trying to retrieve it.. for example:
var number = (from x in myDc.MyList select x.Number).First();
number would actually result in a double of 4.51E-05, not 0.0000451.
I am assuming this can be fixed by using a decimal. If I change the types throughout the generated entities to System.Nullable<decimal> I get type conversion failures.
How should I fix this?
EDIT I think maybe it is better to ask "how should I deal with this"? for example, I can simply convert my double values to decimal later on down the line.. my linq query, for example. If I do that, the example case would return the expected result. That seems clunky, though, and I'd like to correct this at the source.
There are several cases like this where SPMetal will give you clunky code. You can, and sometimes have to, fix that. And I admit, it definitely feels better to do it at the source.
But there is a downside.
When your data model changes you will have to re-run SPMetal to incorporate your new entities. Any changes you made to the generated file will have to be carefully documented and re-done, or your code will be broken. Therefore, I would advise to leave the generated code alone if you can work with it.
If you can write a wrapper around the objects/methods it would of course be preferable to just converting the types at the end-point, but that's general good programming practice.
4.51E-05 actually equals 0.0000451 so there is nothing wrong with your code.
In other words 4.51E-05 means 4.51 times ten to the minus five power, or 0.0000451
using the linqtemplates, I tried getting the linq syntax close to what is in the docs
var query = from c in db.CountyLookups
join s in db.StateLookUps on
c.StateLookupID equals
s.StateLookupID
where c.Name2 == countyName &&
s.Abbr == stateAbbr
select new
{
Latitude = c.Latitude,
Longitude = c.Longitude
};
var result = query.SingleOrDefault();
but when .SingleOrDefault() is called, I get a yellow screen of darn that says:
System.NotSupportedException: The member 'StateLookupID' is not supported
the stack trace ends up at:
SubSonic.Linq.Structure.TSqlFormatter.VisitMemberAccess(MemberExpression m)
the StateLookupID column has underscores in the database and is a regular int pk/fk.
what am I doing wrong?
So apparently VisitMemberAccess has no idea what to do with an int, only string and datetime (starting on line 152 of SubSonic.Linq.Structure.TSqlFormatter). I don't know why this would be called on a join, since a join is usually between an int pk/fk (or guid if you like).
I ended up scrapping the linq query in favor of SubSonic.Query.Select. Here is my new code that works:
var query = db.Select.From<CountyLookup>()
.InnerJoin<StateLookUp>()
.Where(CountyLookupTable.Name2Column)
.IsEqualTo(countyName)
.And(StateLookUpTable.AbbrColumn)
.IsEqualTo(stateAbbr);
I then call ExecuteTypedList and map the results back to my model class. Works like buttah. Just wanted to use linq in this case.
I get this error when I've added properties to my models (the IsValid property as mentioned in ASP.Net MVC 1.0, thanks Rob).
I've had this problem on and off for a bit, and I think I've got it nailed down to the query builder trying to build a query for something that should be done in code, not TSQL.
When it tries to generate the SQL, it descends down the path to generate the TSQL via VisitMemberAccess on a complex type (maybe a another model) but it only knows how to perform operations on datetimes and strings in VisitMemberAccess. I'm sorry if this is a bit incoherent, but I'm trying to get my head around it.
To get around this consider using something like LinqKit AsExpandable prior to any operation which will do the TSQL generation. I've tried this on a simple OrderBy which was going BANG and it appears to work but i have no idea yet what it will do to performance.
Actually I take that back I overcame my problem problem by doing
Stuff.All().Where(x=>x.Someid == id).ToArray()
.AsQueryable()
.Where(x=>x.SomeProp.SomeFlag == true);
It is crud, but it works.
This still appears to be a problem; namely in simple cases such as:
var list = from lang in db.Languages
join site in db.SiteConfigLanguages on
lang.Code equals site.LanguageCode
select lang;
This should evaluate to simple SQL (although pointless in this example):
SELECT Language.* FROM Language LEFT JOIN SiteConfigLanguage ON Language.Code = SiteConfigLanguage.LanguageCode;
It fails inside the same VisitMemberAccess function as (in this case) Language is not a recognisable declaring type (i.e. String or DateTime). It is very similar to the description #matware provided above however it sounds as though the "IsValid" member is pure C# code whereas in this case lang.Code is simply a reference to a column in the database.
I'm currently investigating workarounds as this is only a portion of the larger LINQ query which is failing for me; if I find anything I will post it here. Otherwise, any other solutions/workarounds to this problem known?
UPDATE: Ignore me here; this is simply due to me missing a simple line on the LINQ statement; you need to make sure that you use the "into" keyword to complete things!
i.e.
var list = from lang in db.Languages
join site in db.SiteConfigLanguages on
lang.Code equals site.LanguageCode into sl
from siteLang in sl.DefaultIfEmpty()
select lang;
I've got another error mind you but at least this particular exception is solved. The next one looks a bit nastier unfortunately (inside System.Linq library).