This works:
@Html.TextBox("DateOrdered", string.Format("{0:d}", Model.DateOrdered))
This works:
@Html.TextBox("DateOrdered", string.Format("{0:d}", Model.DateOrdered))
Stick this in your DB Context if you need to have EF recongise more than two decimal places.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// We have a Decimal Field in Our SQL Table decimal(18, 4)
// By default only the first two digits after the decimal will be recognised if this property is set to type decimal
// we need to override this behaviour and here's how
modelBuilder.Entity<MyObjec t>().Property(f => f.totalWeightMg).HasPrecision(18,4);
base.OnModelCreating(modelBuilder);
}
I recently needed to output Boolean values into an iTextSharp PDF document having them represented as Yes or No rather than True or False
Cue MSDN. This article Boolean Structure explains how to do this.
Here's a quick example:
bool JobDone = true; string strJobDone = JobDone ? "Yes" : "No"; // Returns "Yes"
This just caught me out today so hopefully it will help someone else.
Stack Overflow answer here http://stackoverflow.com/questions/3504660/decimal-precision-and-scale-in-ef-code-first
If you have a database field with the spec decimal(18,5) the Entity Framework will still round the number to 2 decimal places by default, so if you enter a number e.g. 15.42700 it will be saved to your database as 15.42000, not very helpful eh. Anyway to fix it you need to override OnModelCreating in your DBContext Class
public class EFDbContext : DbContext { protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder) { modelBuilder.Entity().Property(object => object.property).HasPrecision(12, 10); base.OnModelCreating(modelBuilder); } }
I'm finding myself constantly struggling against the OOB (Out Of Box) features of Sharepoint Foundation 2013 and often need to find ways to interact with Lists in ways that are just not available. Enter the REST API. If, like me, you need to get to grips with using the Sharepoint REST API then I recommend the article SharePoint: Adventures with the REST API Part 1 which is by far the best guide I have found on them t'interwebs.
Recently I've been working on a project where there are several related Lists, in this particular instance a list of Appointments and Patients. So the Appointments List has a Lookup field Patient. By default this gives you a select or drop down list, not ideal if you end up with several items on the list.
I eventually stumbled across SharePoint 2013 Autocomplete Lookup Field. Pretty straightforward to install provided you have server access and works like a charm. Highly recommeded.
I've recently been working on a Sharepoint Project where the client requires their receptionist to be able to send them messages without flooding their email. So they asked for some kind of chat or instant messaging facility. I stumbled across Simple Chat a basic, lightweight JQuery based script which does the job very well.
Implementing the script is really easy. Here's the short version:
Job done.
If you find yourself in the situation where you've messed up with the Content Types in a Sharepoint Site Collection then this will help restore everything back to the default settings:
Open - Start - All Programs - Microsoft Sharepoint Products - Sharepoint Management Shell and run this:
stsadm -o deactivatefeature -name Fields -url http://sitecoll -force
stsadm -o activatefeature -name Fields -url http://sitecoll -force
You need to have individual Forms Based Authentication (FBA) on several different Sharepoint Foundation 2013 Site Collections.
Here's a list of the resources I found which helped get the job done:
You need to add a search function based on model data based on searching both string and int datatypes. If you try the obvious method in your LINQ query as just converting your int field ToString you end up with an error similar to this:
ToString is not supported in linq to entities
Or even this bad boy:
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
After trawling around the forums for a good hour or so I found the following solution. Hope it helps someone else too.
public ActionResult Search(string search = null)
{
int intSearch;
if (!Int32.TryParse(search, out intSearch))
{
}
IEnumerable<Car> cars = context.Cars.Where(
c => search == null
|| c.IntegerField == intSearch
|| c.Manufacturer.Contains(search)
|| c.Model.Contains(search)
);
cars = cars.OrderBy(c => c.Id).ToList();
ViewBag.Search = search;
return View(cars);
}