Solved

LINQ to Sharepoint problem with choice fields

Posted on 2011-03-16
4
1,019 Views
Last Modified: 2012-05-11
I created a list with a choice column called price
Values for example:
5 per user/month
10 per company/month

When I generate the linq to sql entities using spmetal this becomes an enum and it rewrites the values to something like:
_5peruser_month
_10_percompany_month


Then in a repeater I need to show that data, I need to show the real value.

 protected void WrapsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
                return;


            string price = ((Entities.Wrap)e.Item.DataItem).Price.Value.ToString();
            Literal litprice = (Literal)e.Item.FindControl("WrapPrice");
            litprice.Text = price;

        }

what can I do?
0
Comment
Question by:LuisEstebanValencia
  • 3
4 Comments
 
LVL 12

Expert Comment

by:mwochnick
ID: 35149014
I would not recommend using linq to sql to access values in a sharepoint list.  You should use the Sharepoint object model and api.  Microsoft does not guarantee that the database will not change when patching sharepoint, but they make sure the APIs stay the same
Here's a link to the 2007 SDk http://msdn.microsoft.com/en-us/library/ms550992%28v=office.12%29.aspx
and here's a link to the 2010 SDK
http://msdn.microsoft.com/en-us/library/ms550992%28v=office.12%29.aspx
here's an artilce about the 2010 SDK
http://blogs.msdn.com/b/randalli/archive/2010/05/24/download-the-sharepoint-2010-sdk-software-development-kit.aspx
0
 
LVL 12

Expert Comment

by:mwochnick
ID: 35149067
and BTW using the api should return the values in a format you expect
0
 

Author Comment

by:LuisEstebanValencia
ID: 35150251
I am sorry but that was not my question., I need to know how to return the original value in linq. simple question
0
 
LVL 12

Accepted Solution

by:
mwochnick earned 500 total points
ID: 35151770
it appears that the default type mapping from spmetal for choice items is an enum this can be configured to be a string - I don't know if that will give the result you desire

here's a example config file - you probably need to do something similar to the Category Column
<?xml version="1.0" encoding="utf-8"?>
<Web AccessModifier="Internal" xmlns="http://schemas.microsoft.com/SharePoint/2009/spmetal">
  <ContentType Name="Contact" Class="Contact">
    <Column Name="ContId" Member="ContactId" />
    <Column Name="ContactName" Member="ContactName1" />
    <Column Name="Category" Member="Cat" Type="String"/>
    <ExcludeColumn Name="HomeTelephone" />
  </ContentType>
  <ExcludeContentType Name="Order"/>
  <List Name="Team Members" Type="TeamMember">
    <ContentType Name="Item" Class="TeamMember" />
  </List>
</Web>

Open in new window


here's an article on configuring spmetal
http://msdn.microsoft.com/en-us/library/ee535056.aspx
here's an artilcle on configuration Types
http://msdn.microsoft.com/en-us/library/ee536245.aspx
here's a link the the choice/mulitchoice item directly
http://msdn.microsoft.com/en-us/library/ee536245.aspx#BKMK_ChoiceAndMultiChoiceFields

Generate Visual Basic code with custom parameters settings:
SPMetal /web:http://ContosoServer/Marketing /code:MarketingSite.vb /parameters:MarketingSite.xml

Open in new window



0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Da…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question