473,378 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Creating property value cache manager

I need to create Dlinq entity property value caches for every entity and
every property so that
all entity caches can cleared if entity of this type is changed. Entity
class method uses this as:

string GetCustomerNameById( string customerId ) {
var cache = CacheManager.Get<Customer,string, string>("CustomerName");
string res;
if (cache.TryGetValue(customerId , out res))
return res;
res = Nowthwind.Customers.Where(x =x.CustomerId == customerId).Select(x
=x.CustomerName.Single();
cache.Add(customerId , res);
return res;
}

If customer has changed, I call

CacheManager.Clear( typeof(Customer) );

I created class below but got "Type expected" compile error in line shown in
comment.
How to fix ?

Andrus.

using System;
using System.Collections.Generic;

namespace Eetasoft.Eeva.Entity
{
public static class CacheManager
{
struct Key
{
internal Type Entity;
internal string Property;
}

// this causes compile errror: type expected
static Dictionary<Key, Dictionary<,>CacheList = new
Dictionary<Key, Dictionary<,>>();

/// <summary>
/// Gets existing or creates new property cache.
/// </summary>
public static Dictionary<TKey, TValueGet<TEntity,TKey,
TValue>(string propertyName)
{
var key = new Key() { Entity = typeof(TEntity), Property =
propertyName };
Dictionary<TKey, TValuecache;
if (CacheList.TryGetValue(key, out cache))
return cache;
cache = new Dictionary<TKey, TValue>();
CacheList.Add(key, cache);
return cache;
}

/// <summary>
/// Clear the cache if entity has changed.
/// </summary>
/// <param name="entity"></param>
public static void Clear(Type entity)
{
foreach (var key in CacheList.Keys)
{
if (key.Entity == entity)
CacheList.Remove(key);
}
}
}
}

Jun 27 '08 #1
1 2863
The open-type syntax (Dictionary<,>) is only valid in the context of
typeof(), usually in anticipation of MakeGenericType(). It is not
legal for a field/variable, which must use a closed-type, such as
Dictionary<string,object>.

Marc
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: xixi | last post by:
i am using db2 udb v8.1 on win 64 bit, i found this on my db2diag.log 2003-11-12-13.20.05.550001 Instance:DB2 Node:000 PID:1840(db2syscs.exe) TID:3068 Appid:AC100453.G761.00F8D15749BE...
8
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1;...
6
by: Tom Kiefer | last post by:
Question: If I have an ASP.NET User Control which defines/exposes a property that the page can use to specify a mode or data subset for the control to use, is there a way to tell the @OutputCache...
7
by: Robin | last post by:
In a current .Net solution (using VB.Net) has a 3 tier architecture of Web interface, Data Access Layer and Database. How do I implement business logic and class layers into this solution?
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
1
by: Gerhard | last post by:
How can I create a new contact in exchange server from a vb.net web application?
2
by: Moses | last post by:
Hi All, Is is possible to catch the error of an undefined element while creating an object for it. Consider we are not having an element with id indicator but we are trying to make the object...
10
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... We've been trying to migrate our asp.net apps off older, underpowered hardware to newer, bigger boxes but when we do, we see our databases start to melt. When I started to look into it,...
1
by: WT | last post by:
Hello, I have a dictionary made with objects which contain a control element, the control element is added to a Page when I want to edit the dictionary content. I put this dictionary in cache...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.