Solved

LINQ to Sharepoint problem with choice fields

Posted on 2011-03-16
4
1,004 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
Comment Utility
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
Comment Utility
and BTW using the api should return the values in a format you expect
0
 

Author Comment

by:LuisEstebanValencia
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The Scenario: Let’s say you have a quote worksheet in Excel that you use to work up sales figures and such for your clients. You utilize SharePoint to manage and keep track of these documents. You would like values from your worksheet to populate Sh…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

13 Experts available now in Live!

Get 1:1 Help Now