Working through this step by step guide.
I am trying to create the inheritance between BirthAppointment / tblAppointment. However I need the Discriminator Property to be set to appCatId.
The appCatId is held within tblAppointmentType. How can I access this.
alt text http://www.zero7web.com/RegBook-linq.jpg
Thanks in advance for your help.
Clare
Am I understanding correctly that you want BirthAppointment to inherit from tblAppointment? If this is the case, discrimnator property is a field in the database table that used to distinguish records that represent tblAppointment objects from BirthAppointment objects. As such, you can't use appCatId since it lives in another table (tblAppointmentType).
You need to use Visual Studio's Properties window.
http://msdn.microsoft.com/en-us/library/bb531247.aspx
Related
I need a way to insert (or use an already implemented property that could serve as) a unique identifier into a Microsoft.Office.Interop.Excel.ListObject instance.
The problem is that when I'm creating a new ListObject as:
var excelTable = worksheet.ListObjects.Add(ExcelInterop.XlListObjectSourceType.xlSrcExternal, DUMMY_CONNECTIONSTRING, false, true, cellRange);
I cannot rely on the Name property of excelTable to browse for it in the collection since the user could change the value of that property anytime afterwards.
After browsing trough the object properties I found nothing I could use out of the box (like a Tag property for example, which exists in a Microsoft.Office.Tools.Excel.ListObjecttype of object I cannot use at this point due to dependencies) ...and other weird stuff like a DisplayName that appears not only unable to be set directly but also to reflect the exact same value that the Name property has at all times (Why would you want to have 2 properties that reflect the same value at any time?).
I've thought on either creating my own implementation of this class or probably use the Comment property to store a GUID (which I don't know why kinda feels wrong):
excelTable.Comment = Guid.NewGuid().ToString();
Can you suggest of another way to accomplish this task?
Thanks a lot!
It is quite frustrating that there is no "Tag" (or similar) property that you could set on Excel objects. I'm facing the same issues as you. Here are two options that you can use:
alternative text property (for the table it is only visible by right clicking the table, selecting table and alternative text). This is probably a bit cleaner than Comment since the UI for comment is always visible.
you could also generate a wrapper object that contains a direct reference to the ListObject. So one wrapper object for each created ListObject. This works fine until you save / open the workbook again. If you need to be able to identify the table again after reopening the workbook you would still need to write some id to Comment or Alternative text. You could probably do a clean implementation by using events like BeforeSave and AfterSave (add alternative text before save so it saves to disk, then remove it again after save so that the user doesn't see it. When the workbook opens you load up your wrapper objects and remove the alternative text).
I am just getting into EF. For the past 2 years I have been coding database code by hand and finally got fed up with it. I am having one issue when it comes to using enums with E.F. All my previously coded enums used display attributes so that when bound in xaml to a data form or any other control, would display friendly names instead of code names. EX display "Light Brown" instead of "LightBrown or light_brown" etc. All the enum designer allows is to set values and names. Is there a way to get these auto enums to show a different name when bound to?
[Display(Name="Light Brown")]
Light_Brown,
Edit
I am not looking how to convert enum names into friendlier names. I already know how to do that. My issues is accessing the auto generated code for enumerations that are automatically generated using the entity framework designer. It seems there is a way to reference an external code file so I am going to look into this.
Found a question and answer here on stack. You can circumvent this issue by using the "Reference External Type" option in the designer. This is only a solution in the event you are using the database first design of Entity Framework and not the model first design.
Entity Framework 5 Enums with Description attribute using Database First
The author answered his own question under the comments of his question.
Try using
[Description("Light Brown")]
Light_Brown,
Check out this answer you might need to add a converter.
I have two objects (WS.Customer and EF.Customer). The reason for this is my vendor didn't expose all of the fields in their object (WS.Customer) and I need to insert and update into those fields.
I need to merge WS.Customer -> EF.Customer and later merge EF.Customer -> WS.Customer. EF.Customer will have some extra fields that WS.Customer won't have, but when the field names match - I want the values merged.
I also only want to merge values where the destination field is null, empty, or a default value in case of a Guid.
I know I could use to Linq to query each object and build the other, but is there a less verbose way of doing things? I have some other objects I need to use this approach for and don't feel like spending a weeks typing away.
Thanks
You can use one of the available object-to-object mappers library like AutoMapper or EmitMapper. They will take care of copying the data in both directions and skip fields if properly configured. For example with EmitMapper your code might look like this:
ObjectMapperManager.DefaultInstance
.GetMapper<WS.Customer, EF.Customer>(<your configuration object here>)
.Map(customerSource, customerDestination);
What do you mean by "merged"? I guess you need to "translate" from one instance to another, i.e. copy values when name and type of property matches. Please have a look at the implementation provided in ServiceStack, the extension method of object - TranslateTo method: https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack.Common/ReflectionExtensions.cs#L31
Trying a simple project to create my own (very basic) data binding.
I have a class FIELD_DESCRIPTOR which stores meta information about a database column. There will be a further class FIELD which represents the actual field, which will contain a reference to its corresponding FIELD_DESCRIPTOR class.
I am getting stuck in 2 places.
First, I need to have a property in the FIELD_DESCRIPTOR class that stores what kind of Windows Forms control the field is mapped to at the front end. for e.g. I need a property, say, MAPPED_CONTROL_TYPE. And I should be able to store either TextBox, ComboBox etc in this property. Should I just use a string property and be done with it ? Or is there a better way ? Ideally, I'd like to use some kind of enumeration of control types.
Secondly, I need to store a reference / handle to the actual control the field it mapped to. (I think I can do this by passing a reference of the actual control on the form.)
How do I implement this ? What kind of dataType should be used to define this property ?
(Using .Net 3.5, No WPF)
Thanks and regards.
First, I need to have a property in the FIELD_DESCRIPTOR class that
stores what kind of Windows Forms control the field is mapped to at
the front end. for e.g. I need a property, say, MAPPED_CONTROL_TYPE.
And I should be able to store either TextBox, ComboBox etc in this
property. Should I just use a string property and be done with it ? Or
is there a better way ? Ideally, I'd like to use some kind of
enumeration of control types.
The fully qualified type name springs to mind, e.g. System.Windows.Forms.TextBox. This should be unique, and could always be used for dynamic creation if needed.
Secondly, I need to store a reference / handle to the actual control
the field it mapped to. (I think I can do this by passing a reference
of the actual control on the form.)
You could indeed store the reference using a type such as System.Windows.Forms.Control. If you do, be carefult that you don't create a memory leak. i.e. When you control is no longer needed, you should no longer hold its reference in your lookup otherwise you will stop it being disposed.
I am new to SharePoint developement and have a few startup problems which I hope you will help me with.
I am trying to make a custom field type and I am using WPS builder to create the project. Right now I have the following files which are all compiling just fine :)
SuperLookup3.cs
SuperLookup3Control.cs
SuperLookup3FieldEditor.cs
SuperLookup3FieldEditor.ascx (controltemplate)
fldtypes_SuperLookup3.xml (XML)
I have tried look at this example but I just can't get it to work.
My questions
How is the relationsships between the files?
I can see an override of UpdateFieldValueInItem() which is setting the value to the selected item of a dropdown list. But this method is never called (when debugging). How can this be?
Some general advice would be to post this question to the SharePoint Stack Exchange site (if this answer is unsatisfactory), since there are a lot more SharePoint developers there.
From what I understand of that example, it seems to be quite a complex Custom Field Type to start with (given that it has multiple values). There's a good straightforward and pretty well explained tutorial on MSDN that you might want to try out: Walkthrough: Creating a Custom Field Type
Here's a brief explanation of your files (and the classes they contain):
This is the main class of your field, which derives from the SharePoint field base class (SPField). Your naming seems to indicate you're creating a lookup derivative; if so, you may wish to derived from SPFieldLookup.
This is the class the creates the form control displayed on a list item's New, Edit, and Display forms (but not the List View). It's a go-between for the forms and the item's value for this field.
&
This is the section displayed on the Add/Edit Column page. I would expect 3. to have the ending '.ascx.cs' instead of '.cs', since it is the code-behind for 4.; which may be the cause of your problem. This control sets up your field; associating the class in 1. to the list.
This is the field declaration. It says to SharePoint "Hey, I've created my own field; go look here to find it.", and directs SharePoint to the class in 1., which makes the field available on the Add Column page.