Browse by Tags
All Tags »
C# 3.0 (
RSS)
Today I’ve encountered a strange problem running expressions - I wanted to created an expression tree that looks something like this: (e) => e.Owner != null && e.Owner.ID = 4455 So I’ve used the Expression.MakeBinary method to create a binary expression and passed it an ExpressionType.And enum, thinking this is the C# “&&” operator. When running the expression on an e instance that had no owner (null), I got an exception. When looking at the created expression it looked something...
MetaLinq project now supports serializing expression trees with XmlSerializer. For further information about this project, read my previous post on the subject.
I've blogged before (in hebrew) about the difficulty of serializing expression trees to XML. To conclude my hebrew post, I've found a project in CodePlex, called MetaLinq which might be the solution to the problem - this open source allows to perform Linq queries over expression trees, and as a consequence, might allow serialization of the navigable expression tree. I've worked in past few days to fix the code of the project to allow serializing the tree with DataContractSerializer. The...
When you build a EF schema, it automatically plant the name of the imported tables schema into the EDMX file. But alas, what happens when you work in different environments (such as Dev, Test, Prod...) and in each database, the schema of the tables is different? Basically you either reset all your databases to use the same schema or worse - change the EDMX and recompile the assembly before updating the wanted environment. But there is another solution, not a clear one, probably not a supported one...
I've received a couple of request to write some of my previous posts in English so that all other 99.7% of the developers community in the world which finds these subjects interesting can understand what I'm writing. The following post is a translation to English of this Hebrew post . When Entity Framework (EF for short) was designed, Microsoft decided the loading of entities will be during run-time in a JIT like mechanism. They achieved this by using the lazy loading technique - access the...
אחד מהדברים השימושיים ב-3.0 #C, אע"פ שהוא מעט הוזנח במצגות השונות, הוא עץ הביטויים (Expression Tree) שהוא הדבק שמחבר את Lambda Expressions ו-Linq. מאחר ובאמצעות Expression Tree אפשר לייצג ביטוי לוגי, מצאתי לו שימוש במערכת בה הביטויים הלוגיים הם דינאמיים, המבנה שלהם נשמר ב-DB והם צריכים להיבנות ולהיבדק בזמן ריצה. אבל... בדבר אחד Expression Tree נכשל - אי אפשר לבצע לו סריאליזציה. הדבר מוסבר בפורומים השונים, כדוגמת כאן , והסיבות נשמעות די הגיוניות: המחלקות השונות של Expression Tree מכילות מאפיינים...
להלן בעיה - בהנתן Property כלשהו, נניח ששמו FirstName, עליכם להעביר למתודה את שם ה-Property כמחרוזת, תחת המגבלות הבאות: אינכם יכולים לרשום במפורש את שם ה-Property כמחרוזת ("FirstName") אינכם יכולים להשתמש ב-GetProperties, איכשהו לאתר את ה-PropertyInfo ולחלץ את שמו ממאפיין Name (לדוגמה - איתור ה-PropertyInfo הראשון שמתחיל ב-F ואורך שמו הוא 9) לפני כשנתיים נתקלתי בבעיה זו, כאשר וחיפשתי דרך לפתור את הבעיה שהוצגה בפוסט הקודם - העברה של שמות מאפיינים למתודה וקבלת ערכיהם (אז לא עלה בדעתי להשתמש...
ברצוננו לכתוב מתודה אשר תקבל שם קובץ חדש ורשימת קבצים בתיקייה ותחזיר שם קובץ תקין שאינו קיים בתיקייה (כמו שיצירת קובץ חדש בתיקייה תחת וינדוס יוצרת קבצים בשם "new", "new1", "new2" וכו'). string GetUniqueFileName(List<File> files, string newFileName) נוכל לכתוב מתודה אשר עוברת על רשימת הקבצים בתיקייה (List כלשהו) ומחפשת עפ"י מאפיין שם קובץ (obj.FileName) אם השם תפוס ואם כן, להוסיף לשם שהועבר איזשהו Suffix ולנסות שוב עד למציאת שם תקין. עכשיו בואו נסבך - נניח...
כפי שאתם יודעים, אחד מהחידושים של C# 3.0 הוא Partial Method שמאפשר לנו לכתוב מתודות Partial ולממשן (או שלא) בקובץ נפרד. אחד המקומות שמשתמשים לדוגמה ב-Partial Method הוא בקוד המחולל מסכמת EDMX של Ado.Net Entity Framework. במסגרת פרויקט שעשיתי לאחרונה הייתי צריך לבנות דיאגרמת EDMX תכנותית, לייצר ממנה קוד CS ולקמפל את הקובץ שנוצר ל-DLL. השלבים שיש לבצע הם : בניית קובץ EDMX - הסבר בפוסטים הבאים בניית CS מתוך ה-EDMX (או ליתר דיוק, מתוך ה-CSDL שבתוכו). זאת ניתן לעשות באמצעות מחלקות ה-Designer של Entity...