How can I use ref in WCF? - wcf

Can't I use ref in WCF to return data ?
This is my WCF file.
public myDataset SearchInfo(string accountName, string accountId, ref
int totalRecords)
Although totalRecords is a non-zero number, I always get 0.
I have to get both myDataset and totalRecords.
How should I try?
I am new to WCF.
Thanks in advance.
UPDATE :
It works well. My bad !!!

If you're trying to return multiple values, it's probably better to add a data contract with a data member for each value (dataset and total records in your case).
[DataContract]
public class SearchInfoResult
{
[DataMember]
public myDataSet DataSet {get; set;}
[DataMember]
public int TotalRecords {get; set;}
}

Related

Change name of entity in a list in WCF

I am writing a WCFservice that exposes a list to front end. It will be like:
public List<customers> getCustomers()
{
//code goes here like DB operations
}
Here customer List Contains following files
int Id{set;get;}
int CustomerName{set;get;}
int CustomerPlace{set;get;}
Here in this list I want Id being displayed as CustomerId. I cannot change the name of field as I am using some autommaper for database. So is there any thing which can Change Id to Customer Id?
Please Help me to solve this.
Thanks in advance
Only for display purpose means create Custom model Like this
[DataContract]
public class Customers
{
[DataMember]
[Display(Name = "CustomerId")]
public int Id{set;get;}
[DataMember]
public int CustomerName{set;get;}
[DataMember]
public int CustomerPlace{set;get;}
}
[MetadataType(typeof(Customers))]
public partial class customers
{ }
and use List like this public List<Customers> getCustomers()

PetaPoco mapping properties within properties

I am new to PetaPoco and initially I was liking it but then hit a wall which I simply dont know how to search for.
I have a object which needs to set a property within one of its properties, ie Job.Min.BaseValue. The source of this data is "min_mb".
So basically my object is not a direct mapping of the source table
public class Usage
{
public Decimal BaseValue {get;set;}
public Decimal BaseScale {get;set;}
public Decimal BaseUnit {get;set;}
}
[PetaPoco.TableName("data")]
[PetaPoco.PrimaryKey("date, client_name")]
[PetaPoco.ExplicitColumns]
public class Job
{
[PetaPoco.Column("date")]
public DateTime Date {get;set;}
[PetaPoco.Column("client_name")]
public String ClientName {get;set;}
public Usage Min {get;set;}
public CommvaultJob() { Min = new Usage() { BaseScale=1024, BaseUnit="MB" }; }
}
I think you're just missing the extra type when you call Fetch or Query. This worked for me :
Calling PetaPoco :
var allData = _db.Fetch<TestJobPoco,Usage>("select * from dataTEST");
return View( allData);
The pocos :
[PetaPoco.ExplicitColumns]
public class Usage
{
public Usage()
{
BaseScale=1024;
BaseUnit="MB";
}
[PetaPoco.Column("base_value")]
public Decimal BaseValue {get;set;}
[PetaPoco.Ignore]
public Decimal BaseScale {get;set;}
[PetaPoco.Ignore]
public string BaseUnit {get;set;}
}
[PetaPoco.TableName("dataTEST")]
[PetaPoco.PrimaryKey("id")]
[PetaPoco.ExplicitColumns]
public class TestJobPoco
{
[PetaPoco.Column("id")]
public int Id {get;set;}
[PetaPoco.Column("date")]
public DateTime Date {get;set;}
[PetaPoco.Column("client_name")]
public String ClientName {get;set;}
public Usage Min {get;set;}
public TestJobPoco()
{
//Min = new Usage() { BaseScale=1024, BaseUnit="MB" };
}
}
My test database has an id, date, client_name and base_value columns. The primary key is id so it's slightly different than yours but this shouldn't change the way the poco mapping happens.
If your objects do not map with the table structure, an ORM can't help much.
You will need to do the mapping manually or made new shadow properties that copy the values of the other fields, but this added complexity will defeat the purpose of an ORM.

RavenDB Index on SubClasses

I am trying to create an indexes for ProviderProfileId, Email, and Address1
I have created queries that work, but not indexes. I know the inheriting from List for the collections might be part of the problem. List is a carry over from when I had to do a significant amount of XmlSerialization on much older projects, and became a habit in my modeling. I also noticed that in Raven the serialization is much cleaner that if AddressCollection were just List. Any thoughts?
Model is similar to
public class Customer {
public string Id {get;set}
public string Name {get;set;}
public AddressCollection {get;set;}
public SocialMediaAliasCollection {get;set;}
}
public class SocialMediaAliasCollection:List<SocialMedialProfile>{}
public class SocialMediaProfile{
public string ProviderProfileId {get;set;}
public string Email {get;set;}
}
public class AddressCollection:List<Address>{}
public class Address{
public string Address {get;set;}
public string City {get;set;}
public string State {get;set;}
public string Zip {get;set;}
}
I now answered it, basically I didn't know linq well enough. Makes sense once I figured it out. I was trying to make an index for a sub collection, in this case addresses. Not 100% this works, but it does compile and when I push the index to the server it does not blow up.
Map = collection => from item in collection where item.AddressCollection != null
from item2 in item.AddressCollection
select new {
item2.city
}

NHibernate: Discriminators without inheritance

I have the following model:
public class SomeObject1 {
public virtual Guid Id {get; set; }
public string Property1 {get; set; }
}
public class SomeObject2 {
public virtual Guid Id {get; set; }
public string Property2 {get; set;}
}
and the table
SOME_OBJECTS
PK_SOME_OBJECTS Guid
WHICH_OBJECT Integer
PROPERTY1 varchar2
PROPERTY2 varchar2
when the WHICH_OBJECT column = 1 the row contains information for SomeObject1, when the WHICH_OBJECT column = 2 the row contains information for SomeObject2.
How would I go about doing these mappings? I've found the discriminator feature but it seems to only apply when you have subclasses in an inheritance hierarchy.
I'm pretty sure it's not possible to map two unrelated entities to the same table; however, you may be able to map them to two different views that reference the same table.

nHibernate Criteria query with missing mapping

I'm trying to do the following thing:
ICriteria criteriaSelect =
session
.CreateCriteria(typeof(Employees))
.CreateCriteria("Orders")
;
var test = criteriaSelect.List<Orders>();
With:
public class Orders{
public virtual int OrderID { get; private set;}
}
public class Employees{
public virtual int EmployeeID { get; private set;}
public virtual IList<Orders> Orders { get; private set; }
}
And I get the error: "No persister for: Employees".
Please note that for decoupling reason, I don't want Orders to
reference Employees.
Thanks for your help,
Stephane
The Criteria API is for indicating the specification you want during the query. You will need to establish mappings for your entities using either the older hbm.xml files or using Fluent NHibernate. See chapter 5 on Basic O/R Mapping for more details.