Solved

LINQ to Sharepoint problem with choice fields

Posted on 2011-03-16
4
1,008 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Last week I faced a strange issue recently, i have deployed SharePoint 2003 servers for one project and one of the requirements was to open SharePoint site from same server. when i was trying to open site from the same server i was getting authentic…
If you create your solutions on SharePoint sooner or later you will come upon a request to set  permissions of the item depending on some of the item's meta-data - the author, people assigned as approvers, divisions, categories etc. The most natu…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now