Sunday, February 24, 2008

How Do U Make A Moonstone Ring

Greetings from the heart magician!

02/24/2008

My old friend greet heart mage can. For a week I have been working again at the former flash project. During this time I once took care of the worst bugs me in the fall of the Script were crawled (which would probably spend the winter there, I hope they have not laid eggs ...).

It was very hard, again read in all the functions and variables, but luckily I wrote many comments in the script text.


Now I'm here to integrate, in the battle zone water two more monsters.

Wednesday, January 2, 2008

Cancer Sympathyquotes

Several tables to an entity map

are usually stored normalized data in a database. In the application you want but often work with the non-normalized data. Is the ADO.NET Entity Framework is the solution?

Yes and no is the answer. And to put it forward to take away, a mapping is possible from multiple tables to one entity, but only if they have a 1:1 relationship. That is, in most cases you will be better off if created in the database an appropriate view, this is mapped to the entity and the Update, Insert and Delete stored procedures to be solved.

But the solution. First, a model is created with the wizard, which contains all the tables.

The adjustments to the Conceptual Model (CSDL) are simple. On the desired attributes of the entity from the other tables are added. For example, here the entity Cars to the attribute value has been enhanced.

\u0026lt;xml: namespace prefix = edmx /> \u0026lt;edmx:conceptualmodels>
\u0026lt;schema xmlns = "http://schemas.microsoft.com/ado/2006/04/edm" alias = " Self "namespace =" Model ">
\u0026lt;entitycontainer name="Entities">
\u0026lt;entityset name="Cars" entitytype="Model2.Cars">
\u0026lt;/ entitycontainer>
\u0026lt;EntityType name="Cars"&#062
&#060key&#062
&#060propertyref name="ID_Cars"&#062
&#060/key&#062
&#060property name="ID_Cars" nullable="false" type="Guid"&#062&#060/property&#062
&#060property name="Brand" type="String" maxlength="50"&#062&#060/property&#062
&#060property name="Model" type="String" maxlength="50"&#062&#060/property&#062
&#060property name="Value" type="String" maxlength="50"&#062&#060/property&#062
\u0026lt;/ EntityType>
\u0026lt;/ schema>
\u0026lt;/ edmx: conceptualmodels>

adjustments to the storage model (SSDL) are not necessary because of the database, which is represented by this model will not change.

by adjusting the mapping of the newly defined attributes on the entity now in the existing storage model mapped. This is achieved by adding an additional fragment mapping.

\u0026lt;edmx:mappings>
\u0026lt;Mapping xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS" space="CS">
&#060entitycontainermapping cdmentitycontainer="Entities" storageentitycontainer="dbo"&#062
&#060entitysetmapping name="Cars"&#062
&#060entitytypemapping typename="IsTypeOf(Model.Cars)"&#062
&#060mappingfragment storeentityset="Cars"&#062
&#060scalarproperty name="ID_Cars" columnname="ID_Cars"&#062
&#060scalarproperty name="Brand" columnname="Brand"&#062
&#060scalarproperty name="Model" columnname="Model"&#062
&#060/mappingfragment&#062
&#060mappingfragment storeentityset="Extensions"&#062
\u0026lt;scalarproperty name="ID_Cars" columnname="ID_Extensions">
\u0026lt;scalarproperty name="value" columnname="Value">
\u0026lt;/ MappingFragment>

\u0026lt;/ EntityTypeMapping & # 062
\u0026lt;/ EntitySetMapping>
\u0026lt;/ EntityContainerMapping>
\u0026lt;/ mapping>
\u0026lt;/ edmx: mappings> Do not

code as needed and EntitySets AssociationSet are CSDL and the To delete mapping.

Wednesday, December 19, 2007

St John's Wort Help With Confidence

From the name to the instance with DynamicMethod

A customer places during logging LogMessages different (different Classes) in a database. It shall state the type of message stored (LogMessage class name), the message itself as well as other fields in the table.
should now read the entries and the original objects are restored.

For this solution the obvious way with Reflection was chosen:

string s = "Namespace.Name.FromDB";
Assembly.GetAssembly Assembly a = (typeof (this class));
a.GetType Type t = (s );
base type b = (base type) Activator.CreateInstance (t);

Since this is not very performant, the code has improved as follows:

string s = "Namespace.Name.FromDB";
Assembly Assembly.GetAssembly a = (typeof (this class));
Type t = a.GetType (s);
ConstructorInfo i = t.GetConstructor (Type.EmptyTypes);
base type b = (base type) i.Invoke (null);

Where the class name and the associated ConstructorInfo in a static Dictionaire be stored so they do not have to be re-evaluated on every call. Thus we have from the second to nth call the desired performance gain. The code looks like this.

ConstructorInfo c = null;
if (_cinfo.TryGetValue (s, out c)) {

c = t.GetConstructor (Type.EmptyTypes);
lock (_cinfo)

{if (_cinfo.ContainsKey (s) )
{
_cinfo.Add (s, c);}

}}


yet elegant and much better performance you go with Dynamic Methods. The value returned by the dynamic method delegate is as previously passed the ConstructorInfo in a Dictionaire and for subsequent calls reused:

public delegate BaseType CtorDelegate ();

DynamicMethod dm = new DynamicMethod
(MyCtor ", typeof (base type), Type.EmptyTypes, typeof (base type) modules).
ILGenerator Ilgen dm.GetILGenerator = ();
ilgen.Emit (OpCodes.Newobj, t.GetConstructor (Type.EmptyTypes)); ilgen.Emit
(OpCodes.Ret) ;
CtorDelegate d = (CtorDelegate) dm.CreateDelegate (typeof (CtorDelegate));

The call is then just as short (d previously read from the Dictionnaire) and incredibly fast:

message = t (t) d ();

Now we just need everything to be beautifully packaged in a factory class and finished . More on this subject including performance measurements can be found as always with Google ;-)