How to disable CRM 2011 Xrm caching? - caching

I have problem with crm 2011 caching. I don't need it, but I don't know how to disable it.
First I generate this:
CrmSvcUtil.exe
/codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization,
Microsoft.Xrm.Client.CodeGeneration" /out:Outputcs
/url:https://crmaddress/XRMServices/2011/Organization.svc
/username:usr/password:pw
/namespace:ns/serviceContextName:XrmServiceContext
then I have the following code:
private XrmServiceContext _crmService;
public CrmWS()
{
CrmConnection _connection = new CrmConnection();
_connection.ServiceUri = new Uri("https://url");
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = new NetworkCredential("1","2","3");
_connection.ClientCredentials = credentials;
_connection.ClientCredentials.UserName.UserName = "1";
_connection.ClientCredentials.UserName.Password = "2";
_crmService = new XrmServiceContext(_connection);
var l = _crmService.EntitySet.where(m => m.name == "a").ToList();
}
What should I do to turn off caching?

Specify the service in your configuration file:
<microsoft.xrm.client>
<services>
<add name="Xrm" type="Microsoft.Xrm.Client.Services.OrganizationService, Microsoft.Xrm.Client"/>
</services>
</microsoft.xrm.client>

Another bypass I found which can be used, its not perfect and people might give me bad reviews.
But you can always use a query which always changes with a random number or other random code:
Random r = new Random();
int rInt = r.Next(-100000000, 100000000);
var l = _crmService.EntitySet.where(m => m.name == "a" && m.name!=rInt.ToString()).ToList();

Related

ef6 linq method returning $ref for nested entries in query

my linq method system from EF6 is returning $ref when I monitor results in fiddler. If I watch the local window in my webapi everything is populated correctly, but not in the actual results that are returned. It only affects the nested entries. anyone know what I am doing wrong? (I created models from database in EF6)
var student = dbEF.Accounts
.Where(x => x.AccountNumber == acctNum)
.Select(x => new DTOCrmDetails()
{
AccountNumber = x.AccountNumber,
CommissionId = x.CommissionId,
Commission = x.Commission,
ManagerID = x.ManagerID,
ManagerName = x.Manager.ManagerName,
Manager = x.Manager,
Employees = x.Manager.Employees,
WireInstructionsUSD = x.Manager.WireInstructionsUSDs
//Mapping_ManagersExecutingBrokers = x.Manager.Mapping_ManagersExecutingBrokers
}).FirstOrDefault();
return student;
these are my settings.
var json = config.Formatters.JsonFormatter; json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects; config.Formatters.Remove(config.Formatters.XmlFormatter); config.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented; config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
You need to disable your lazy loading in the entity framework dbcontext.
something like this way:
dbEF.Configuration.LazyLoadingEnabled = false;

Visual Studio Online SDK

I am working on a project where I have a requirement to create workitem on Visual Studio Online instance. I am using personal access token. This will set CreatedBy as my name (Expected behavior). I am considering to use Oauth2; However, I am not sure if there's the way to do this Server-to-Server (Non-Interactive)? Any suggestions thoughts?
var personalAccessToken = "PAT Value fro Config";
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "", personalAccessToken))));
return client;
PAT's are created in Security context of the user. I need to find a way to use Oauth without having to involved UI. So I'm looking for Server-to-Server Auth.
object[] patchDocument = new object[5];
patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = bugTitle };
patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.TCM.ReproSteps", value = bugReproSteps };
patchDocument[2] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "1" };
patchDocument[3] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Severity", value = "2 - High" };
patchDocument[4] = new { op = "add", path = "/fields/System.IterationPath", value = deserializeIteration };
//System.IterationPath
string postUrl = $"{_vsoInstanceUrl}/DefaultCollection/ProjectName/_apis/wit/workitems/$Bug?api-version=1.0";
await ExecutePatch(patchDocument.ToArray(), postUrl, "application/json-patch+json");
No there is no Server-to-Server OAuth support. If you use the .NET Client Object Model you can leverage Impersonation support.
If your account has "Act on behalf of others" permissions you can also achieve a "User X via YourAccount".

Magento: Retrieve a list of Groups from a Attribute Set

I need to retrive a list of all groups of a certain attribute Set, given by the ID or name for example via API.
To do so, I've checked the API here (http://www.magentocommerce.com/api/soap/catalog/catalogProductAttributeSet/productAttributeSet.html) but it seems there's no way to list groups, only create, update and delete is possible.
What can I do to get the id of a certain group?
Thanks.
MNC_Product_Sync.catalogProductAttributeGroupRepositoryV1Service.catalogProductAttributeGroupRepositoryV1PortTypeClient mage_client= AttributeGroup;
MNC_Product_Sync.catalogProductAttributeGroupRepositoryV1Service.CatalogProductAttributeGroupRepositoryV1GetListRequest nn = new MNC_Product_Sync.catalogProductAttributeGroupRepositoryV1Service.CatalogProductAttributeGroupRepositoryV1GetListRequest();
MNC_Product_Sync.catalogProductAttributeGroupRepositoryV1Service.FrameworkFilter filter = new MNC_Product_Sync.catalogProductAttributeGroupRepositoryV1Service.FrameworkFilter();
MNC_Product_Sync.catalogProductAttributeGroupRepositoryV1Service.FrameworkFilter[] filters = new MNC_Product_Sync.catalogProductAttributeGroupRepositoryV1Service.FrameworkFilter[1];
filter.field = "attribute_set_id";
filter.value = "31";
filter.conditionType = "eq";
filters[0] = filter;
//MNC_Product_Sync.MagentoService.FrameworkFilter filter1 = new MNC_Product_Sync.MagentoService.FrameworkFilter();
MNC_Product_Sync.catalogProductAttributeGroupRepositoryV1Service.FrameworkSearchFilterGroup fg = new MNC_Product_Sync.catalogProductAttributeGroupRepositoryV1Service.FrameworkSearchFilterGroup();
fg.filters = filters;
MNC_Product_Sync.catalogProductAttributeGroupRepositoryV1Service.FrameworkSearchFilterGroup[] fgg = new MNC_Product_Sync.catalogProductAttributeGroupRepositoryV1Service.FrameworkSearchFilterGroup[1];
fgg[0] = fg;
MNC_Product_Sync.catalogProductAttributeGroupRepositoryV1Service.FrameworkSearchCriteriaInterface search = new MNC_Product_Sync.catalogProductAttributeGroupRepositoryV1Service.FrameworkSearchCriteriaInterface();
search.filterGroups = fgg;
search.pageSize = 100;
nn.searchCriteria = search;
try
{
var response = mage_client.catalogProductAttributeGroupRepositoryV1GetList(nn);
}

Is Dynamics CRM 2013 sdk cache result of QueryExpresions by Default?

I wrote this simple query:
var connectionString = String.Format("Url={0}; Username={1}; Password={2}; Domain={3}", url, username, password, domain);
var myConnection = CrmConnection.Parse(connectionString);
CrmOrganizationServiceContext _service = new CrmOrganizationServiceContext(myConnection);
var whoAmI = _service.Execute(new WhoAmIRequest());
var query = new QueryExpression
{
EntityName = "phonecall",
ColumnSet = new ColumnSet(true)
};
query.PageInfo = new PagingInfo
{
Count = 20,
PageNumber = 1,
PagingCookie = null
};
query.Orders.Add(new OrderExpression
{
AttributeName = "actualstart",
OrderType = OrderType.Descending
});
query.Criteria = new FilterExpression() { FilterOperator = LogicalOperator.And };
query.Criteria.AddCondition("call_caller", ConditionOperator.In, lines);
var entities = _service.RetrieveMultiple(query).Entities;
I have a program which runs this query every minute. On the first execution the correct results are displayed but for subsequent queries the results never change as I update records in CRM.
If I restart my program the results refresh correctly again on the first load.
Why are the results not updating as records are modified in CRM?
It is the CrmOrganizationServiceContext that is doing the caching - I found the following worked a treat and the results of my RetrieveMultiple are no longer cached :)
Context = new CrmOrganizationServiceContext(CrmConnection.Parse(connectionString));
Context.TryAccessCache(cache => cache.Mode = OrganizationServiceCacheMode.Disabled);
RetrieveMultiple always brings back fresh results so there must be some other aspect of your program which is causing stale data to be displayed.

Problem In Updating the existing record in subsonic 3.0

private Boolean Saveuser(bool isNew)
{
tb_User user = new tb_User();
user.User_Name = txtUserName.Text.Trim();
user.User_LoginName = txtLoginName.Text;
user.User_Password = txtPassord.Text;
user.User_ModifiedBy = clsGlobalVariable.strusername;
user.User_Modified = DateTime.Now;
user.User_IsDeleted = false;
user.User_IsUpdated = true;
user.User_UserGroup = "";
user.User_UserType = "";
user.User_WarehouseCode = "";
user.SetIsNew(isNew);
user.Save();
}
when I try to insert new user using above coding, it is worik, but try to update existing user by passing isNew (false). It is not working, when I trace inside activerecord.cs, the dirty column count is always 0 for both new and update. How can I update the existing record?
Please answer for me?
Thanks.
You should
Get the record
Update record
Save
User u = User.FetchByID(2345);
u.User_Name = "blablabla";
//other User object modifications...
u.Save();

Resources