Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

LINQ to Sharepoint problem with choice fields

Posted on 2011-03-16
4
Medium Priority
?
1,077 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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline

916 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