Yahoo announced that it has ended its meetings with Microsoft in favour of a search-related deal as well as the sale of the entire company. Yahoo is expected to move forward with an advertising pact with Google.
According to Yahoo’s press release, issued Thursday afternoon:
Yahoo!’s Board of Directors has determined, after careful evaluation, that such a transaction would not be consistent with the company’s view of the converging search and display marketplaces, would leave the company without an independent search business that it views as critical to its strategic future and would not be in the best interests of Yahoo! stockholders.
Needless to say that Yahoo’s shares are responding quite well to these events
Technorati Tags: Microsoft
This is a little snipplet i’ve been using over the years in several tasks and it’s purpose is to get a listing of all class names that belong to a given namespace. For this we’ll be using the System.Reflection namespace:
public Collection FindAllnamespaceClasses(string namespaceName)
{
Assembly currentAssembly = Assembly.GetExecutingAssembly();
// Set list to hold all namespaces
List namespaceList = new List();
// Set list to hold all namespace classes
Collection classList = new Collection();
foreach (Type type in currentAssembly.GetTypes())
{
if (type.Namespace.ToUpper().Contains(namespaceName))
namespaceList.Add(type.Name);
}
// Loop through all the classes and add them
foreach (string className in namespaceList)
classList.Add(className);
return classList;
}
And that’s it. This will return all the classes that belong to the specified namespace. If you need to infer over namespaces belonging on a different assembly, line 3 should use the Assembly.GetAssembly() method, and pass a type belonging to that same namespace as parameter.
Technorati Tags: C#
The June 2008 tech Preview of the PKS project is now available on codeplex. This version is a technical demo of what PKS is, and what it will offer. Expect a production version to be released by September 2008.
For those who don’t know, podcasting Kit for SharePoint® (PKS) is an accelerator for social media, using podcasting and social networks to deliver the next generation knowledge management solution to Microsoft customers. Built on top of Microsoft® Office SharePoint® Server 2007 and Silverlight 2, PKS delivers an integrated experience with a wide variety of devices including PC, Zune™, Windows Mobile phones and other podcast capable devices.
Keep in mind that it’s a community and partner project, it is not supported by Microsoft, and it requires Microsoft® Office SharePoint® Server 2007.
Technorati Tags: Sharepoint
I’ve been recently working on a nifty project in wich the primary purpose is to search for media data in the database. It’s a normal ASP.NET application, based on the 3.5 version of the .NET framework - nothing new here. The great news is the Linq to Entities platform I’m building it on. This is indeed a very usefull technology and this is my first project using Linq to Entities.
This is the scenario: We have objects, and objects have properties. The goal of this article is to be able to search the storage for objects by using a global text search affecting their properties. I will give this article a slow start, trying to explain the general methodology of creating entity objects and, generally, our EDM (Entity Data Model).
At this point, I’m working on the SP1 Beta of Visual Studio, wich includes .NET Framework 3.5 SP1 Beta and ADO.NET Entity framework. You can get it here. The included .NET Framework 3.5 Service Pack 1 adds many new features and fixes, including the following:
- .NET Framework Client Release (“Arrowhead”)
- ASP.NET Dynamic Data
- ASP.NET Routing
- ADO.NET Data Services
- ADO.NET Entity Framework
After generating my EDM, from the ADO.NET Entities designer (selected Add -> New Item… -> ADO.NET Entity Data Model, and selected my database objects), my EntityContext was created, containing all my objects, relational attributes, and QueryProperties. Everything went well. We are now able to start querying our store for data.
That said, my goal is to do a generic search over a metadata object called MetaObj. But here’s the catch: I don’t want a explicit method with object properties using Linq query code like this:
IQueryable list = from e in entities
where e.Property1.ToUpper().Contains(someText) ||
e.Property2.ToUpper().Contains(someText) ||
e.Property3.ToUpper().Contains(someText) ||
...
select e;
This way, I get stuck with MyObject and its properties. Instead, I want to be able to dinamically generate a Linq text search query based on any object’s properties. The solution to this is using a bit of reflection to get the object’s characteristics,query them using Expression trees to map my restrictions, and then apply them to my Linq object query.
As you know, Linq was a major inovation in c# 3.0. Its purpose is to improve the way data is manipulated and represented and at the same time facilitate the development procedures and bridge the gap between data fetching and its consumption in many architectural practices. As an example, the following code:
SqlConnection conn = new SqlConnection("...");
conn.Open();
SqlCommand cmd = new SqlCommand(@"SELECT p.ProductID, p.ProductName FROM Products p WHERE p.ProductName = @productName", conn);
cmd.Parameters.AddWithValue("@productName", "XPTO");
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
string ID = dr.GetString(0);
string ProductName = dr.GetString(1);
}
dr.Close();
Is now replaces by this:
var db = new MyDataContext();
var myImpliciyObject = from p in db.Products
where (p.ProductName == "XPTO")
select new { ID = p.ProductID, Name = p.ProductName };
string ID = myImpliciyObject.ID;
string ProductName = myImpliciyObject.Name;
What .NET compiler is doing behind the scenes is to transform this code into an intermediate language representation (IL), which will be rewrited into something like this:
var myImpliciyObject = db.Products.Where(p => p.ProductName = "XPTO").Select(p => new { ID = p.ProductID, Name = p.ProductName });
… which is nothing more than two expressions, with their input parameters on the left and expression on the right. This approach is called Method based query, and uses the Where and Select query operators. Their arguments are called Lambda Expressions. A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types. From here, the compiler gets rid of the lamba expressions (they will become anonymous methods) and the anymous type syntax (that is converted into constructor call of an auto-generated class with two properties).
With this type of method construction, we can specify an abstract query to any relational data repositories that can later be translated into their propper domain-specific syntax. Take SQL for instance. The last piece of code would be rendered as:
SELECT p.ProductID, p.ProductName FROM Products AS p WHERE p.ProductName = 'XPTO'
This is where Expression Trees come in handy. An expression tree as the name implies, is a branched relationship between expressions. Each expression can be, for instance, a simple calculation operation, a property member access or a conditional expression.
So, in order to resolve this challenge, lets get started by setting our EntityContext and get our EntityObject’s properties list…
PropertyInfo[] entityProperties = typeof(MyObject).GetProperties();
ObjectQuery entities = MyEntities.MyObject;
…and since our expressions will access our object’s properties, we must define our object as a parameter. So, we will declare and initialize a ParameterExpression variable with MyObject as argument:
// Define input parameter as MyObject
ParameterExpression param1 = Expression.Parameter(typeof(MyObject), typeof(MyObject).Name);
Next we define List<> collection object that will hold our expressions during the iteration, and general expression objects to hold the member property value call and value comparison:
List>> listExpressions = new List>>();
Expression callExpr;
Expression valueExpr;
Expression exp = null;
Expression> lambdaExp = null;
Expression> finalExp = null;
During property iteration we will set the callExpr Expression as an access to a property value, and then “join it” with the value expression by calling the Contains() method of string data type. Notice that for each data type we can have different treatments. This is because we want to be able to compare both text and numeric values against our properties. In case of string values we will use Expression.Call to create a MethodCallExpression that represents a call to an instance method by calling the appropriate factory method. In our case, we need it to invoke the Contains() method of the string data type witch, by the way, is later translated into its sql-domain-specific restriction clause, like:
CAST(CHARINDEX(UPPER(@p__linq__1), UPPER([Extent1].[PropertyName])) AS int)) > 0',N'@p__linq__1 nvarchar(1)',@p__linq__1=N''
(The @p__linq__1, is our property value that is to be compared with user value)
As for other property data types we just use the Expression.Equal to create a BinaryExpression that represents an equality comparison:
foreach (PropertyInfo prop in entityProperties)
{
// Reset valid property
valid = false;
// Reset expression
exp = null;
// Left expression will check a MyObject property value
// We could also use Expression.Property here
callExpr = Expression.MakeMemberAccess(param1, prop);
Type t = prop.PropertyType;
if (t == typeof(string))
{
// Property value will be comprared to the input value
valueExpr = Expression.Constant(value);
exp = Expression.Call(callExpr, typeof(string).GetMethod("Contains", new Type[] { typeof(string) }), valueExpr);
valid = true;
}
else if (t == typeof(int) || t == typeof(Nullable) ||
t == typeof(long) || t == typeof(Nullable) ||
t == typeof(short) || t == typeof(Nullable))
{
// Check if input data type matches
object num = null;
long temp;
if (long.TryParse(value, out temp))
num = temp;
if (num != null)
{
valueExpr = Expression.Constant(num, t);
exp = Expression.Equal(callExpr, valueExpr);
valid = true;
}
}
else if (t == typeof(DateTime) || t == typeof(Nullable))
{
DateTime date;
if (DateTime.TryParse(value, out date))
{
valueExpr = Expression.Constant(date, t);
exp = Expression.Equal(callExpr, valueExpr);
valid = true;
}
}
else if (t == typeof(bool) || t == typeof(Nullable))
{
bool val;
if (bool.TryParse(value, out val))
{
valueExpr = Expression.Constant(val, t);
exp = Expression.Equal(callExpr, valueExpr);
valid = true;
}
}
if (valid)
{
lambdaExp = Expression.Lambda>(exp, param1);
listExpressions.Add(lambdaExp);
}
}
In the end, our listExpression Expression list will hole all the Expressions we need to query all available properties. The final step is to “glue” them together using a bitwise OR operation:
// Add up all conditions using an OR expression type
foreach (Expression> e in listExpressions)
{
if (finalExp == null)
finalExp = e;
else
finalExp = Expression.Lambda>(Expression.Or(finalExp.Body, e.Body), param1);
}
// Define query
IQueryable listOfMyObjects = entities.Where(finalExp);
And that’s it. With this you can query all object properties for a given value whether it’s text or numeric. It’s a great way to search for object values without writing specific code against them.
Technorati Tags: Entity Framework
In an Entity Framework enviroment, the generated EDM (Entity Data Model) provides us with all the information we need to map our database schema. (In fact, that isn’t entirely true. Unfortunately default values aren’t mapped into its relative objects. But since that’s not the issue here, I’ll adress that in a later post).
Whenever you need, you can check each of your Entity object’s properties and attributes in order to find its schema on your database. One common question in the Entity Framework community is: How do I get all the primary keys of an Entity Object (EntityKey’s). Well, the answer is simple: all you need to do is check each property’s custom attributes, and see if the EdmScalarPropertyAttribute attribute has the EntityKeyProperty value set to true, like this:
PropertyInfo[] entityProperties = typeof(Entidade).GetProperties();
List keyList = new List();
foreach (PropertyInfo prop in entityProperties)
{
object[] attrs = prop.GetCustomAttributes(false);
foreach (object obj in attrs)
{
if (obj.GetType() == typeof(EdmScalarPropertyAttribute))
{
EdmScalarPropertyAttribute attr = (EdmScalarPropertyAttribute)obj;
if (attr.EntityKeyProperty)
keyList.Add(prop.Name);
}
}
}
Technorati Tags: Entity Framework

As you all probably know, Internet explorer Beta 2 will be available in August, and with it, probably some new development issues that developers shoud be prepared for.
Every new browser version release comes filled with changes destined to improve compliance and (supposedly) make it more meaningfull. The problem is, some websites of today might experience problems with this new release.
Well, apparently Microsoft added a new feature in internet explorer that allows you to specify wich version of IE is your application targeting. With this information, upcoming versions of Internet Explorer will be able to validate and render it acoordingly to the specified version.
To do so, add the following meta tag to the head of your pages. This tag will tell future versions of IE that your pages were designed for IE7.
<meta http-equiv="X-UA-Compatible" content="IE=7" />
This way it will know that the page should be rendered like IE 7.
Technorati Tags: Internet Explorer 8
For all the bloggers out there who share the passion of software technologies and provide code samples in their web content, here’s a hint for you: it’s called CopySource as HTML. It’s a Visual Studio 2008 Addon that copies your source code as HTML, ready to paste into your blog posts.
Here’s the result:
43 ///
44 /// Gets the title for the article categories.
45 ///
46 /// The article collection.
47 public static string ArticleCollection
48 {
49 get
50 {
51 return GetSafeConfig(“ArticleCollection”, “Article Categories”);
52 }
53 }
To install, just download this file, and extract its content to your Visual Studio 2008 Addons Folder.
Win XP Users: C:\Documents and Settings\\My Documents\Visual Studio 2008\Addins
Vista Users: C:\Users\\Documents\Visual Studio 2008\Addins
Tip: Set a keybind for it in Tools>Options>Enviroment>Keyboard. That should make things faster.
Technorati Tags: Visual Studio 2008